forecaster
forecaster

Reputation: 1159

gnuplot animation multiple data files hold on after do loop

I'm animating from two data files.

I need to "hold-on" after first do loop and then replot second do loop for animation.

See below an example:

set term gif size 400,400 animate delay 100 loop 0 optimize font 'Verdana,10' crop
set output "output.gif"
set yrange [0:4]                                        
set xrange [0:5]

$data1 << EOD
2.24448 0.270645    1.00    1.00
3.24448 0.270645    0.500   1.20
1.24448 0.411645    0.600   1.60
EOD

$data2 << EOD
3.24448 2.50645    0.400    1.00
0.24448 2.30645    0.800   1.20
1.24448 2.50000    0.300   0.60
1.55448 2.21645    0.300   1.30
EOD

stats $data1 using 1:4 nooutput
n1 = int(STATS_records) - 1

stats $data2 using 1:4 nooutput
n2 = int(STATS_records) - 1

plot x

do for [i=0:n1] {
    replot $data1 u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "red" notitle
}

do for [i=0:n2] {
    replot $data2 u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "blue" notitle
}

set output

The output is as follows: The red vectors are created from data1 and blue vectors are created from data2.

I want to first animate the red vectors and hold on and then start animating blue vectors. As it stands now, when the blue vector appears red vector disappears and reappears. I just want to simply start animating red vector 1 by one and then followed by blue vector.

See below: Red vector appears as planned, but as soon as blue vector appears, red vector disappears and then starts to animate, I just want to follow the sequence, first plot red vector and hold on and then continue to animate blue vector.

enter image description here

Upvotes: 1

Views: 364

Answers (1)

theozh
theozh

Reputation: 26068

I guess replot has a special behaviour... (but I don't remember the details). Therefore, I would do it without replot as follows.

Code:

### animated vectors
reset session
set term gif size 400,400 animate delay 100 optimize font 'Verdana,10' crop
set output "output.gif"
set yrange [0:4]
set xrange [0:5]

$data1 << EOD
2.24448 0.270645    1.00    1.00
3.24448 0.270645    0.500   1.20
1.24448 0.411645    0.600   1.60
EOD

$data2 << EOD
3.24448 2.50645    0.400    1.00
0.24448 2.30645    0.800   1.20
1.24448 2.50000    0.300   0.60
1.55448 2.21645    0.300   1.30
EOD

stats $data1 using 1:4 nooutput
n1 = int(STATS_records) - 1

stats $data2 using 1:4 nooutput
n2 = int(STATS_records) - 1

plot x

do for [i=0:n1] {
    plot x, \
    $data1 u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "red" notitle
}

do for [i=0:n2] {
    plot x, \
    for [j=0:n1] $data1 u 1:2:3:4 every ::0::j w vectors lw 1.5 lc rgb "red" notitle, \
    $data2 u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "blue" notitle
}
set output
### end of code

Result:

enter image description here

Addition: (merging 3 or more files)

Data:

File1.dat

2.24448 0.270645    1.00    1.00
3.24448 0.270645    0.500   1.20
1.24448 0.411645    0.600   1.60

File2.dat

3.24448 2.50645    0.400    1.00
0.24448 2.30645    0.800   1.20
1.24448 2.50000    0.300   0.60
1.55448 2.21645    0.300   1.30

File3.dat

4.0  1.0  -1.0   1.0
1.0  2.0   0.5   0.7
4.0  3.0  -1.0  -0.5
1.0  3.0   0.5  -1.0

Code:

### animated vectors from several files
reset session
set term gif size 400,400 animate delay 100 optimize font 'Verdana,10' crop
set output "output.gif"
set yrange [0:4]
set xrange [0:5]

set table $Arrows
    plot 'File1.dat' u 1:2:3:4:('0xff0000') w table
    plot 'File2.dat' u 1:2:3:4:('0x0000ff') w table
    plot 'File3.dat' u 1:2:3:4:('0x00ff00') w table
unset table

plot x

do for [i=1:|$Arrows|] {
    plot x, \
    $Arrows u 1:2:3:4:5 every ::0::i-1 w vec lw 1.5 lc rgb var notitle
}
set output
### end of code

Result:

enter image description here

Upvotes: 1

Related Questions