Gnuplotting

Create scientific plots using gnuplot

November 7th, 2012 | 6 Comments

Assume you have a data file describing a trajectory that you would like to animate like the spiral shown in Fig. 1.

moving spiral

Fig. 1 An animated spiral trajectory (code to produce this figure, data)

In order to create the animation we have to produce a set of png images and create the resulting gif animation with GIMP as shown in the Animation I – gif entry. Therefor, we have to tell gnuplot at which point of the data it has to stop for each image. This can be achieved by the every option. The point at the end of the line is just one data point. Here the start point and end point for every are just the same.

do for [ii=1:99] {
    splot 'spiral.txt' every ::1::ii w l ls 1, \
          'spiral.txt' every ::ii::ii w p ls 1
}

The downward spiral is created by running the loop in the other direction.

do for [ii=99:1:-1] {
    splot 'spiral.txt' every ::1::ii w l ls 1, \
          'spiral.txt' every ::ii::ii w p ls 1
}

By the way, I don’t know why the antialiasing of the output png images is not working in this example. If you have any idea, feel free to tell me.Assume you have a data file describing a trajectory that you would like to animate like the spiral shown in Fig. 1.

6 Comments

  1. pipaul says:

    I can’t understand this line
    “splot ‘spiral.txt’ every ::1::ii”

    and this one
    ” set output sprintf(‘png/spiral%03.0f.png’,n)”

    explain their function

  2. Virgile Genin says:

    Hello.
    I tried to plot an animation with this example, but as my datafile is very big, the animation is becoming more and more slow. I did’t try to save it as gif, and i would know if it will apear in my gif ? we can i do for not having this problem ?

    sorry for my bad English
    i am waiting for any answer

  3. Dedalus says:

    Hi there. I was trying to understand the procedure, so I’ve tried to do the specific example by downloading the spiral.txt data file, and the spiral.gnu with the code. Then I run in the terminal “gnuplot spiral.gnu” and I get this error message:

     gnuplot spiral.gnu
    
    ;
        n=n+1;
        set output sprintf('png/spiral%03.0f.png',n);
        splot 'spiral.txt' every ::1::ii w l ls 1,           'spiral.txt' every ::ii::ii w p ls 1;
    
                                                                 ^
    cannot open file; output not changed
    line 29: util.c: No such file or directory
    

    What did I do wrong?

  4. hagen says:

    Thanks for reporting this. The error is thrown, because gnuplot cannot find the png directory, in which it tries to store the generated png files.
    I have update the spiral.gnu file by adding the following line, which works under Linux:

    system('mkdir -p png')
    
  5. halo says:

    Thanks for your code and website?
    I tweak it and get this https://wx2.sinaimg.cn/mw690/7daf486dly1frtoy31buzg209q07an2r.gif

  6. hagen says:

    Cool, thank you. I uploaded your figure to post it here, if you don’t mind:

    trajectory

    Fig. 2 Another animated trajectory