简短版本:
gnuplot的“ replot”命令似乎没有绘制任何内容。在输出中仅显示原始图(“图...”)。
长版:
我有一个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
工作正常。但是,由于我的实际程序有些复杂(这是非常简化的),因此简单地串联一个额外的行而不会有破坏脚本的风险(例如,不带命令的参数)实际上是不可行的。无论哪种方式,我都想知道为什么“重新绘制”似乎不能以这种方式工作(或更可能是我做错了什么)。谢谢!
答案 0 :(得分: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
不支持该页面,您只会看到第一张图。