0
votes

I have a data file containing n coordinate positions at t time steps of c number of figures which I would like to create an animation of in a gif file using gnuplot.

The data file is setup giving the n coordinate positions of all c figures at each time step, as

x1,1 y1,1
x1,2 y1,2
.
.
.
x1,n y1,n
x2,1 y2,1
.
.
.
xc,n yc,n

At each time step, I want to plot all n positions of my c figures in my gif animation.

The following code isn't exactly working.

set terminal gif animate
set output "output.gif"

do for [i=1:time_final] {
do for [j=1:c] {
plot "file.dat" every 1::(i-1)*(j-1)*n::i*j*n-1 u 1:2 w filledcurves
}}
set output

I apologize for the newbie-ness of this question.

1
Please read up on How to Ask on StackOverflow. More specifically, show us what you have tried, and why it doesn't work. - Antimony
Thank you, I updated my post following your suggestion. - brenna_hogan

1 Answers

0
votes

I think that the every statement needs a small adjustment. Each of your "time steps" contains in total c*n records. Point numbers in Gnuplot in the context of every keyword are 0-based. This means that time-step i (assuming that the first one has i=1 as in your do loop) begins at point (i-1)*c*n. In order to move to "figure" j (assuming again that the first one within each time step has j=1), we need to add an offset of (j-1)*n. Now, since each "figure" has n points, the offset of the last point within each figure is n-1. In total:

do for [i=1:time_final] {
    stepOffset = (i-1)*c*n
    do for [j=1:c] {
        firstPoint = stepOffset + (j-1)*n
        lastPoint = firstPoint + (n-1)
        plot "file.dat" every ::firstPoint::lastPoint u 1:2 w filledcurves
}}

In case you would want to merge the c "figures" into one plot, you could do:

do for [i=1:2] {
    stepOffset = (i-1)*c*n
    plot for [j=1:c] "file.dat" every ::(stepOffset + (j-1)*n)::(stepOffset + (j-1)*n + (n-1)) u 1:2 w filledcurves
}

By the way, since your data file has only two columns, the w filledcurves style seems to be misplaced here, if you want to fill the area between the curve and for example x-axis, w filledcurves x1 should work...