shell - gnuplot replot 不绘图

标签 shell gnuplot

简短版本:

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

效果很好。然而,由于我的实际程序中的一些复杂性(这是极其简化的),简单地连接这样的额外行而不冒破坏脚本的风险(例如,有参数而没有命令)是不太可行的。不管怎样,我想知道为什么“重新绘制”似乎不起作用(或者更可能是我做错了什么)。谢谢!

最佳答案

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 不支持这一点,您只能看到第一个图。

关于shell - gnuplot replot 不绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52336723/

相关文章:

awk - 使用 awk 根据文件名在 gnuplot 中设置数据系列的标题

Gnuplot 误读时间数据

graph - Gnuplot:使用矩阵格式的 4d 颜色图

gnuplot - 通过 gnuplot 在 Maxima 中绘制线性回归和残差

bash - 为什么我的 sed 操作不起作用?

Bash 控制流使用 ||在功能上,用 set -e

linux - Linux shell 中的命令组

shell - 检查文本文件中的两个变量

linux - 为什么 'top | grep > file' 不起作用?

gnuplot - 我想拟合一个带有整数参数的函数