xmgrace中-nxy与-pipe选项能否联用实现无临时文件多列绘图?
Absolutely, you can do this! The issue with your original somecommand | xmgrace -pipe is that by default, xmgrace's pipe mode only reads the first two columns (x and y1) as a single dataset, ignoring the rest. To get all four y columns plotted against x, you just need to explicitly tell xmgrace to parse the input as multiple columns using the -nxy flag in a read block command.
Here's the command that will work:
somecommand | xmgrace -pipe << EOF read block -nxy $(cat -) EOF
How this works:
- The
<< EOFstarts a here-document that sends commands directly to xmgrace's pipe interface. read block -nxytells xmgrace to interpret the incoming data exactly like it would with the command-line-nxyoption: the first column is x, and each subsequent column becomes a separate y dataset.$(cat -)reads the output fromsomecommand(piped in) and feeds it straight into theread blockcommand.
This will generate four distinct curves (y1 vs x, y2 vs x, etc.) just like your original temp file method, but without the intermediate tmp.dat file.
If you prefer a more concise one-liner, process substitution works too:
xmgrace -pipe < <(echo "read block -nxy"; somecommand)
This combines the control command and your data into a single input stream for xmgrace, achieving the same result.
内容的提问来源于stack exchange,提问作者Saurish Chakrabarty

