我正在尝试使用从stdin获取的数据生成两行的绘图.我有一个文件"test.csv":
0,1.1,2
1,2,3
2,6,4
4,4.6,5
5,5,6
Run Code Online (Sandbox Code Playgroud)
我一直试图用这样的命令来绘制这个,
$ cat test | gnuplot -p -e "set datafile separator \",\"; plot '-' using 1:2 with lines, '' using 1:3 with lines;"
Run Code Online (Sandbox Code Playgroud)
但无论我尝试什么,
line 5: warning: Skipping data file with no valid points
Run Code Online (Sandbox Code Playgroud)
我认为这是因为对于第二行,stdin已经用尽了.有没有办法让gnuplot从stdin的每一列中获取不同图的数据?
谢谢.
Pon*_*ars 15
" - "用于指定数据遵循plot命令.因此,如果您使用它,您将需要执行以下操作:
echo "set datafile separator \",\"; plot '-' using 1:2 with lines, '' using 1:3 with lines;" | cat - datafile.dat | gnuplot -p
Run Code Online (Sandbox Code Playgroud)
(上面引用可能需要转义).
你在找什么是这样的:
plot '< cat -'
Run Code Online (Sandbox Code Playgroud)
现在,您可以:
cat test | sed ... | gnuplot -p "plot '< cat -' using ..."
Run Code Online (Sandbox Code Playgroud)
请注意,如果您使用带有绘图的选项,则可能需要多次通过stdin输入输入数据,如下所示:
cat testfile testfile | gnuplot -p "plot '< cat -' using 1, '' using 2"
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,testfile必须以一行中包含唯一字符"e"的行结束.
bde*_*dew 11
我设法通过两次发送数据来解决这个问题,在每个块之后在它自己的行上以"e"结束.所以你的输入应该是这样的
set datafile separator ","; plot '-' using 1:2 with lines, '' using 1:3 with lines
0,1.1,2
1,2,3
2,6,4
4,4.6,5
5,5,6
e
0,1.1,2
1,2,3
2,6,4
4,4.6,5
5,5,6
e
Run Code Online (Sandbox Code Playgroud)
Gnuplot可以从stdin读取,但是对于每个plot语句,都需要一个新的数据集.以下工作正常:
cat test.csv | gnuplot -p -e "set datafile separator ','; plot '-' using 1:2 w l"
Run Code Online (Sandbox Code Playgroud)
一旦附加第二个绘图命令,就会出现错误, '' using 1:3
.为此,您需要再次发送数据,因为第一个数据集不是为了重用而存储的.因此,对于您的两个绘图命令,以下代码段工作正常:
echo 'e' | cat test.csv - test.csv | gnuplot -p -e "set datafile separator ','; plot '-' using 1:2 w l, '' using 1:3 w l"
Run Code Online (Sandbox Code Playgroud)
将数据文件写入两次,用一个e
表示第一个绘图命令的数据结尾.