0
votes

Suppose I have the following sample data file.

0   1   2
0   3   4   
0   1   9
0   9   2
0   19  0
0   6   1
0   11  0
1   3   2
1   3   4   
1   1   6
1   9   2
1   15  0
1   6   6
1   11  1
2   3   2
2   4   4   
2   1   6
2   9   6
2   15  0
2   6   6
2   11  1

first column gives value of time. Second gives values of x and 3rd column y. I wish to plot graphs of y as functions of x from this data file at different times,

i.e, for t=0, I shall plot using 2:3 with lines up to t=0 index. Then same thing I shall do for the variables at t=1.

At the end of the day, I want to get a gif, i.e, an animation of how the y vs x graph changes shape as time goes on. How can I do this in gnuplot?

1

1 Answers

1
votes

What have you tried so far? (Check help ternary and help gif)

You need to filter your data with the ternary operator and then create the animation.

Code:

### plot filtered data and animate
reset session

$Data <<EOD
0   1   2
0   3   4   
0   1   9
0   9   2
0   19  0
0   6   1
0   11  0
1   3   2
1   3   4   
1   1   6
1   9   2
1   15  0
1   6   6
1   11  1
2   3   2
2   4   4   
2   1   6
2   9   6
2   15  0
2   6   
2   11  1
EOD

set terminal gif animate delay 50 optimize
set output "myAnimation.gif"

set xrange[0:20]
set yrange[0:10]
do for [i=0:2] {
    plot $Data u 2:($1==i?$3:NaN) w lp pt 7 ti sprintf("Time: %g",i)
}
set output
### end of code

Result:

enter image description here

Addition:

The meaning of $1==i?$3:NaN in words:

If the value in the first column is equal to i then the result is the value in the third column else it will be NaN ("Not a Number").