I would like to generate several plots using Gnuplot thats why I need to use loop. The data is loading from files "sort'i'.dat". The code is shown below but it doesn't work. I have got some problem with main loop. I don't know why it doesn't work, maybe it is connected with my version of Gnuplot. Thanks.
do for [i=0:10] {
set term png
set output 'sort'.i.'.png'
set title "Quick sort"
set xlabel "Position number"
set ylabel "Number on position"
unset key
plot 'sort'.i.'.dat' using 1:2 with points pt 5
}
The error is: "line 1: invalid complex constant"
The simplest method to plot multiple data files is to insert a for loop inside the plot command of gnuplot. Assuming you have N files named sequently, i.e.
For best results, however, you should run gnuplot from within X Window, so that you can see better previews of your plots. Entering Data All the data sets you use in gnuplot should be typed into a text file first. There should be one data point per line.
Another great advantage of GnuPlot is that allows the separation of script from data. GnuPlot runs a script, and generally the data is read from a data file specified by the script in the plot command. It likes columnar or tab-separated data, which suits SQL Server.
Producing Printed Output gnuplot is very device-neutral: when producing your plots, it could care less whether it is producing a preview on an X Window display, an ASCII-art version for a terminal, or any other output form. The plot commands will all work the same.
This kind of do for
iteration was introduced in version 4.6.0:
The following iteration works only since 4.6.0:
do for [i=0:10] { print i }
The iteration
plot for [i=0:10] i*x
works also with 4.4
One other option for 4.4, although quite ugly, would be to "outsource" the iterations. Only two of the lines depend on the iteration variable, which make this feasible. You construct all the plot instructions outside of gnuplot and then eval
the complete string:
As an example using bash:
set terminal pngcairo
set title "Quick sort"
set xlabel "Position number"
set ylabel "Number on position"
unset key
set style data points
loopstr = 'set output ''sort%d.png''; plot ''sort%d.dat'' using 1:2 pt 5; '
eval(system('exec bash -c "for ((a=0;a<=10;a++)) do printf \"'.loopstr.'\" \$a \$a; done" '))
For the exec bash
see gnuplot and bash process substitution. Of course you can use any other program to do the iteration.
But this doesn't of course replace the ease of having the gnuplot-internal iterations. Why not upgrade to 4.6?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With