问题描述
我有一个程序,该程序生成带有几个输入参数的数据并将其吐出到stdout,我将此数据通过管道传输到gnuplot并进行绘制(在我的情况下,我没有中间文件):
I have a program that generates data with a couple of input arguments and spits it out to stdout, I pipe this data to gnuplot and plot it (in my case I don't have an intermediate file):
$ cat sample_data.dat | gnuplot plot_script.gp
sample_data.dat:
sample_data.dat:
0 0.5000
1 0.9225
2 0.2638
3 0.7166
4 0.7492
plot_script.gp
plot_script.gp
#!/usr/bin/gnuplot
set terminal wxt size 700,524 enhanced font 'Verdana,10' persist
set style line 1 lc rgb '#0060ad' pt 7 lt 1 lw 0.5 # circle blue thin line
set style line 2 lc rgb '#949599' lt 1 lw 1 # --- grey
plot "<cat" using 1:2 w lp ls 1 notitle
我想完成的事情就是这样
what I want to accomplish is something like this
plot "<cat" using 1:2 w l ls 2 notitle, \
"" using 1:2 w p ls 1 notitle
也就是说,我希望线条使用一种颜色,而点使用另一种颜色.我只是可以找到解决方案.
That is, I want the line in one colour and the dots in another. I just can figure out a solution for this.
我可以将stdin读取为变量来存储它,以便将其绘制两次吗?
Could I read the stdin to a variable to store it so I could plot it twice?
关于stackoverflow的问题有些紧迫,但我没有什么真正可以用来解决我的问题的, gnuplot-plot-two-data-set-from-stdin 和 pipe-plot-data-to-gnuplot-script
There are some close questions on stackoverflow but nothing that I could really use to figure out to fit my problem,gnuplot-plot-two-data-set-from-stdin and pipe-plot-data-to-gnuplot-script
我现在也尝试过这种方法:
I have now tried this as well:
plot for[col=2:3] "<awk '{print $1,$2,$2}'" using 1:col w lp ls col notitle
推荐答案
在将数据发送到gnuplot之前,必须对其进行复制.在类似Unix的系统上实现此目的的一种方法是
You must duplicate your data before you send it to gnuplot. A way to to this on Unix-like systems is
$ cat sample_data.dat | cat - <(echo 'e') | tee - | gnuplot script.gp
并使用您已有的脚本,例如
and using the script which you already have, like
plot '<cat' w l, '' w p
在gnuplot 5中,您还可以在gnuplot内部使用一些技巧,例如
In gnuplot 5 one could also use some trickery inside of gnuplot like
data = system('cat -')
set print $db
print data
unset print
plot $db w l, $db w p
并仅用
gnuplot plot_script.gp < sample_data.dat
这篇关于我如何从stdin读取数据到gnuplot并绘制两次相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!