Reputation: 545
I'm getting confused with how to use for-loops in gnuplot.
The following code works fine:
plot for [quadIter=0:270:90] \
path using 1:(column(1 + quadIter))
It plots 4 curves on one graph.
I also want to plot 4 horizontal lines on the same graph. I have written the following script to do this:
plot for [quadIter=0:270:90] \
path using 1:(column(1 + quadIter)) , \
path_to_expt[1 + quadIter/3: 19] \
But it only plots one additional line on the graph, so it is not being included in the for-loop. Please can you tell me how to get the additional line included in the loop?
Also, the constant value that is plotted is not the value I was expecting it would plot. Please can you tell me how to print the value of quadIter to the screen, so that I can check it against the value in the file?
Finally, I tried just to plot the 4 horizontal lines with this script:
plot for [quadIter=0:270:90] \
path_to_expt[1 + quadIter/3: 19] \
But I got an error message, "Non-numeric string found where a numeric expression was expected". I find this strange, as I didn't get this error message when I ran the second script but, as the second script isn't working how I would like, hopefully by getting the second and third scripts to work, I will have a better understanding of how for-loops work in gnuplot.
Thank you for your help!
Upvotes: 0
Views: 6196
Reputation: 48390
The for
iteration applies only the the current plot expression. The line
plot for [i=1:4] i*x, i*x**2
creates five plots, whereas in order to get eight plots you must do
plot for [i=1:4] i*x, for [i=1:4] i*x**2
Concerning your last expression path_to_expt[1 + quadIter/3: 19]
: array expressions aren't supported by gnuplot (however path_to_expt
looks like one).
Upvotes: 3