6

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"

0

2 Answers 2

7

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?

Sign up to request clarification or add additional context in comments.

6 Comments

Ok but this "plot for [i=0:10] ix" works only for one line but I need it for two lines for the same "i" for: "plot for [i=0:10] ix" and for: "plot 'sort'.i.'.dat' using 1:2 with points pt 5"
The point was to show, that you need at least version 4.6.0. Which version do you have?
I have got 4.4 version.
... and thats the reason why your do for iteration is not working, because for this you need 4.6
I know that but how to do something similar to this in Gnuplot 4.4.
|
0

I had the same problem, and definitely the version of gnuplot is the issue. For example, I was working on gnuplot 1.8.10.0 and I got a message that I showed in the image 1. Then, I installed gnuplot 5.0, and it worked excellent! :).

gnuplot sample 1

gnuplot sample 2

All the best

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.