gnuplot animation 2D vector fields

梦想与她 提交于 2020-07-10 05:34:47

问题


I'm trying to animate 2D vector with gnuplot. I want to show one line i.e, one vector at a time.

My Data Structure is as follows: They x,y,u,v

2.24448 0.270645    1.00    1.00
3.24448 0.270645    0.500   1.20

I'm able to create a static plot sing following command:

plot "datam.dat" using 1:2:3:4 with vectors filled head lw 3

Here is the output:

Here is my question: I would like to animate and show one row (i.e,) one vector at a time, how to accomplish this in GNU plot using GIF?

Thanks


回答1:


Animated GIFs are created with set terminal gif animate. Check help gif for details. Below is a simple example (tested with gnuplot 5.2). You have to make a new plot for each frame. So, put your plot command into a do for-loop. With every ::i::i you are plotting only the ith line (check help every). If you don't know the total number of lines of your datafile, do stats "YourFile.dat" and the variable STATS_records will tell you this number.

Code:

### animated graph with vectors
reset session

set term gif size 300,300 animate delay 12 loop 0 optimize
set output "AnimateVectors.gif"

# create some dummy data
set angle degrees
N = 60
set samples N
set table $Data
    plot [0:360] '+' u (cos($1)):(sin($1)):(sin($1)):(cos($1)) w table
unset table

set xrange[-2.5:2.5]
set yrange[-2.5:2.5]
do for [i=0:N-1] {
    plot $Data u 1:2:3:4 every ::i::i w vectors lw 2 lc rgb "red" notitle
}
set output
### end of code

Result:

Addition:

This would be the non-animated version, e.g. in a wxt-terminal.

Code:

### non-animated graph with vectors
reset session
set term wxt size 400,400

# create some dummy data
set angle degrees
N = 60
set samples N
set table $Data
    plot [0:360] '+' u (cos($1)):(sin($1)):(sin($1)):(cos($1)) w table
unset table

set xrange[-2.5:2.5]
set yrange[-2.5:2.5]
plot $Data u 1:2:3:4 w vectors lw 1.5 lc rgb "red" notitle
### end of code

Result:

Addition2:

Do you maybe mean something like this? A "semi"-animated arrow? By the way, as you can see the arrow look quite different in gif and wxt terminal.

Code:

### "semi"-animated graph with vectors
reset session
set term gif size 300,300 animate delay 12 loop 0 optimize
set output "AnimateVectorsSemi.gif"

# create some dummy data
set angle degrees
N = 60
set samples N
set table $Data
    plot [0:360] '+' u (cos($1)):(sin($1)):(sin($1)):(cos($1)) w table
unset table

set xrange[-2.5:2.5]
set yrange[-2.5:2.5]

do for [i=0:N-1] {
    plot $Data u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "red" notitle
}
set output
### end of code

Result:



来源:https://stackoverflow.com/questions/56942993/gnuplot-animation-2d-vector-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!