gnuplot动画2D矢量场 [英] gnuplot animation 2D vector fields
问题描述
我正在尝试使用gnuplot设置2D向量的动画.我想显示一行,即一次显示一个向量.
I'm trying to animate 2D vector with gnuplot. I want to show one line i.e, one vector at a time.
我的数据结构如下:他们x,y,u,v
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
以下是输出:
这是我的问题:我想设置动画并一次显示一行(即)一个矢量,该如何使用GIF在GNU图中完成此操作?
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?
谢谢
推荐答案
动画GIF是使用set terminal gif animate
创建的.有关详细信息,请检查help gif
.
下面是一个简单的示例(经过gnuplot 5.2测试).您必须为每个帧绘制一个新图.因此,将您的plot命令放入do for
循环中.使用every ::i::i
时,您仅绘制第i
条线(检查help every
).如果您不知道数据文件的总行数,请执行stats "YourFile.dat"
,变量STATS_records
会告诉您该数字.
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 i
th 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.
代码:
### 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
结果:
添加:
这将是非动画版本,例如在wxt
终端中.
This would be the non-animated version, e.g. in a wxt
-terminal.
代码:
### 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
结果:
添加2:
您可能是说类似的意思吗? 半"动画箭头?顺便说一句,正如您所看到的,箭头在gif
和wxt
终端中看起来完全不同.
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.
代码:
### "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
结果:
这篇关于gnuplot动画2D矢量场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!