gpt4 book ai didi

gnuplot stdin,如何绘制两条线?

转载 作者:行者123 更新时间:2023-12-03 10:25:49 24 4
gpt4 key购买 nike

我正在尝试使用从标准输入中获取的数据生成一个包含两条线的图。我有一个文件“test.csv”:

0,1.1,2
1,2,3
2,6,4
4,4.6,5
5,5,6

我一直试图用这样的命令来绘制它,
$ cat test | gnuplot -p -e "set datafile separator \",\"; plot '-' using 1:2 with lines, '' using 1:3 with lines;"

但无论我怎么努力,我都会得到,
line 5: warning: Skipping data file with no valid points

我认为这是因为对于第二行,stdin 已经用完了。有没有办法让 gnuplot 从标准输入的每一列中获取不同图的数据?

谢谢。

最佳答案

“-”用于指定数据遵循 plot 命令。因此,如果您使用它,则需要执行以下操作:

echo "set datafile separator \",\"; plot '-' using 1:2 with lines, '' using 1:3 with lines;" | cat - datafile.dat | gnuplot -p

(上面的引用可能需要转义)。

你要找的是这个:
plot '< cat -'

现在,你可以这样做:
cat test | sed ... | gnuplot -p "plot '< cat -' using ..."

请注意,如果您使用带有绘图的选项,您可能需要通过标准输入多次输入输入数据,如下所示:
cat testfile testfile | gnuplot -p "plot '< cat -' using 1, '' using 2"

在上述情况下,testfile 必须以包含唯一字符 'e' 的行结尾。

Manual reference

关于gnuplot stdin,如何绘制两条线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4585770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com