Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

gnuplot stdin, how to plot two lines?

I'm trying to produce a plot with two lines using data taken from stdin. I have a file "test.csv":

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

I've been trying to plot this with commands like,

$ cat test | gnuplot -p -e "set datafile separator ","; plot '-' using 1:2 with lines, '' using 1:3 with lines;"

But no matter what I try I get,

line 5: warning: Skipping data file with no valid points

I assume this is because for the second line, stdin has already been exhausted. Is there a way to get gnuplot to take data from each column of stdin for different plots?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The "-" is used to specify that the data follows the plot command. So if you use it, you'll need to do something like:

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

(Quoting above probably needs to be escaped).

What're you looking for is this:

plot '< cat -'

Now, you can do:

cat test | sed ... | gnuplot -p "plot '< cat -' using ..."

Note that you might need to feed in the input data via stdin multiple times if you're using options with plot, like so:

cat testfile testfile | gnuplot -p "plot '< cat -' using 1, '' using 2"

In the above case, testfile must end with a line that has the sole character 'e' in it.

Manual reference


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...