将绘图数据管道传输到gnuplot脚本 [英] pipe plot data to gnuplot script
问题描述
我想创建一个包含三个图的gnuplot. 数据应该是内联的(我只想
I want to create a gnuplot with three plots in it. The data should be inline (as I want to only
它应该看起来像这样:
当前,我正在使用以下gnuplot脚本创建绘图:
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
文件data.txt
是:
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
我想将data.txt通过管道传递到gnuplot中,而不要依赖脚本中引用的数据文件.
cat data.txt | gnuplot plot.gnu
之类的东西.
这样做的原因是,我有几个data.txt
文件,并且不想为每个文件建立一个plot.gnu
文件.
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.
我在这个stackoverflow线程中了解了特殊的'-'
文件 ,阅读有关在一个文件中包含多个图的信息.但是,这需要将数据包含在gnuplot代码中,这并不干净.
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.
推荐答案
如果您使用的是Unix系统(即非Windows),则可以使用'<cat'
而不是'-'
来读取stdin:
If you are on a Unix system (i.e. not Windows) you can use '<cat'
instead of '-'
to read from stdin:
plot '<cat' using ...
然后您可以执行cat data.txt | gnuplot script.gp
.但是,在您提到的问题的特定情况下,由于图位于for循环中,因此您读取了3次输入.因此,通过stdin发送数据是不合适的,因为第一次读取数据后,数据就会消失.
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.
这篇关于将绘图数据管道传输到gnuplot脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!