【问题标题】:How do I read data from stdin to gnuplot and plot same data twice如何从标准输入读取数据到 gnuplot 并绘制相同的数据两次
【发布时间】:2015-03-08 00:01:41
【问题描述】:

我有一个程序,它使用几个输入参数生成数据并将其输出到标准输出,我将此数据通过管道传输到 gnuplot 并绘制它(在我的情况下,我没有中间文件):

$ cat sample_data.dat | gnuplot plot_script.gp

sample_data.dat:

0  0.5000    
1  0.9225    
2  0.2638    
3  0.7166    
4  0.7492    

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

我想要完成的事情是这样的

 plot "<cat" using 1:2 w l ls 2 notitle, \
      "" using 1:2 w p ls 1 notitle

也就是说,我想要一种颜色的线和另一种颜色的点。我只是想办法解决这个问题。

我可以将标准输入读入一个变量来存储它,以便我可以绘制两次吗?

关于 stackoverflow 有一些很接近的问题,但没有什么我可以真正用来解决我的问题, gnuplot-plot-two-data-set-from-stdinpipe-plot-data-to-gnuplot-script

编辑:

我现在也试过了:

plot for[col=2:3] "<awk '{print $1,$2,$2}'" using 1:col w lp ls col notitle

【问题讨论】:

    标签: plot pipe gnuplot stdin


    【解决方案1】:

    在将数据发送到 gnuplot 之前,您必须复制数据。在类 Unix 系统上实现此目的的一种方法是

    $ cat sample_data.dat | cat - <(echo 'e') | tee - | gnuplot script.gp
    

    并使用您已有的脚本,例如

    plot '<cat' w l, '' w p
    

    在 gnuplot 5 中,也可以在 gnuplot 内部使用一些技巧,例如

    data = system('cat -')
    set print $db
    print data
    unset print
    plot $db w l, $db w p
    

    并仅使用

    调用此脚本
    gnuplot plot_script.gp < sample_data.dat
    

    【讨论】:

    • 感谢您的回答。我无法访问 gnuplot 5,所以无法尝试。但是我在运行您提供的代码时遇到了一些问题。输出似乎不是确定性的。我随机对双倍数据点进行不同的排序,当我手动复制到正确的结构时,我收到错误warning: Skipping data file with no valid points
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    相关资源
    最近更新 更多