【问题标题】:gnuplot replot not plottinggnuplot replot 不绘图
【发布时间】:2019-02-19 13:08:15
【问题描述】:

简短版:

gnuplot 的“replot”命令似乎没有绘制任何内容。输出中仅显示原始图(“plot ...”)。

长版:

我有一个 shell 脚本在文件数据库中循环,其中一些需要绘制在同一个输出图像中,有些则不需要。我目前的方法是让 shell 脚本编写一个 gnuplot 脚本......大致如下:

输入文件的目录,“数据”

1_1.csv
1_2.csv
1_3.csv
1_4.csv
2_1.csv
...
x_y.csv

shell.sh

for f in data/*.csv
do
    gpFile=scripts/gp_x.gp      # x from input filename
    out=out_x.png               # x from input filename
    if [ ! -e "$gpFile" ]; then       # if gnuplot script does not exist
        cat <<-EOF >$gpFile           # create new file called gp_x.gp
        set datafile separator ","
        set term png size 1024,768
        set autoscale fix
        set output $out
        plot "$f" using 1:2 with lines
        EOF
    else                              # file does exist
        cat <<-EOF >>$gpFile          # append file with more text
        replot "$f" using 1:2 with lines
        EOF
    fi
done

for s in scripts/*.gp  # cycle through all scripts just generated
    gnuplot $s         # run gnuplot scripts
done

因此,shell 脚本会生成许多 gnuplot 脚本,其中一个看起来像这样:

gp_x.gp

set datafile separator ","
set term png size 1024,768
set autoscale fix
set output out_x.png
plot "x_1.csv" using 1:2 with lines
replot "x_2.csv" using 1:2 with lines
replot "x_3.csv" using 1:2 with lines
replot "x_4.csv" using 1:2 with lines

这将导致仅绘制第一个“plot”命令,并且没有完成任何“replot”命令(同样,不会引发错误)。如果我用类似的东西替换它......

plot "x_1.csv" using 1:2 with lines, \
     "x_2.csv" using 1:2 with lines, \
     "x_3.csv" using 1:2 with lines, \
     "x_4.csv" using 1:2 with lines

它工作正常。但是,由于我的实际程序中存在一些复杂性(这非常简化),在没有破坏脚本的风险的情况下简单地连接额外的一行是不可行的(例如,没有命令的参数)。无论哪种方式,我都想知道为什么“重新绘制”似乎不能以这种方式工作(或者,更有可能是我做错了什么)。谢谢!

【问题讨论】:

    标签: shell gnuplot


    【解决方案1】:
    plot "x_1.csv" using 1:2 with lines, \
         "x_2.csv" using 1:2 with lines, \
         "x_3.csv" using 1:2 with lines, \
         "x_4.csv" using 1:2 with lines
    

    创建一个有四行的图。

    plot "x_1.csv" using 1:2 with lines
    replot "x_2.csv" using 1:2 with lines
    replot "x_3.csv" using 1:2 with lines
    replot "x_4.csv" using 1:2 with lines
    

    创建四个图:第一个有一条线,第二个有两条线,依此类推。相当于

    plot "x_1.csv" using 1:2 with lines
    plot "x_1.csv" using 1:2 with lines, "x_2.csv" using 1:2 with lines
    plot "x_1.csv" using 1:2 with lines, "x_2.csv" using 1:2 with lines,  "x_3.csv" using 1:2 with lines
    plot "x_1.csv" using 1:2 with lines, "x_2.csv" using 1:2 with lines,  "x_3.csv" using 1:2 with lines, "x_4.csv" using 1:2 with lines
    

    如果您使用支持多页的终端(如pdfcairo),您将获得四页。png 不支持,您只能看到第一个图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      相关资源
      最近更新 更多