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
665 views
in Technique[技术] by (71.8m points)

pipe plot data to gnuplot script

I want to create a gnuplot with three plots in it. The data should be inline (as I want to only

It should look like this:

https://s22.postimg.cc/qcc94e1i9/test.png

Currently I am using the following gnuplot script to create the plot:

set terminal png
set output "test.png"
plot for[col=2:4] "data.txt" using 1:col title columnheader(col) with lines

The file data.txt is:

Generation Best Worst Average
0 2 1 0
1 3 1 2
2 4 3 3
3 4 3 3
4 6 3 4
5 7 4 5
6 9 6 7
7 10 6 9
8 10 5 6
9 11 6 8
10 12 7 9

I would like to pipe the data.txt into gnuplot and not to rely on the referenced data file in the script. Something like cat data.txt | gnuplot plot.gnu. The reason for this is, that I have several data.txt files and don't want to build a plot.gnu file for each of these.

I read about the special '-' file in this stackoverflow thread and I read about multiple plots in one file. However this would require to include the data with the gnuplot code, which isn't clean.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

If you are on a Unix system (i.e. not Windows) you can use '<cat' instead of '-' to read from stdin:

plot '<cat' using ...

Then you can do cat data.txt | gnuplot script.gp. However, in the specific case you mention in your question, with the plot in the for loop, you read the input three times. So sending the data through stdin is not appropriate, since the data will be gone after the first time it is read.


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

1.4m articles

1.4m replys

5 comments

57.0k users

...