Reputation: 27
The short version:
gnuplot's "replot" command is not seeming to plot anything. Only the original plot ("plot ...") is displayed in the output.
The long version:
I have a shell script cycling through a database of files, some of which need to be plotted in the same output image, some don't. My approach currently is to have the shell script write a gnuplot script ... something along these lines:
directory of input files, "data"
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
So that shell script generates a number of gnuplot scripts, one of which would look like this:
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
This results in only plotting the first "plot" command, and none of the "replot" commands are accomplished (also, no errors are thrown). If I were to replace it with something like...
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
It works fine. However, due to some complications in my actual program (this is extremely simplified), it's not really feasible to simply concatenate an extra line like that without the risk of breaking the script (e.g. having arguments with no command). And either way, I'd like to know why "replot" doesn't seem to work this way (or, more likely, what I'm doing wrong). Thanks!
Upvotes: 2
Views: 2094
Reputation: 4095
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
creates a single plot with four 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
creates four plots: the first with one line, the second with two lines, and so forth. It is equivalent to
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
If you used a terminal that supports multiple pages (like pdfcairo
) you would get four pages.png
does not support that, and you see only the first plot.
Upvotes: 3