for*_*ter 1 animation gnuplot vector gif animated-gif
我正在尝试使用 gnuplot 制作 2D 矢量动画。我想显示一行,即一次显示一个向量。
我的数据结构如下:它们x,y,u,v
2.24448 0.270645 1.00 1.00
3.24448 0.270645 0.500 1.20
Run Code Online (Sandbox Code Playgroud)
我可以使用以下命令创建静态图:
plot "datam.dat" using 1:2:3:4 with vectors filled head lw 3
Run Code Online (Sandbox Code Playgroud)
这是我的问题:我想制作动画并一次显示一行(即)一个向量,如何使用 GIF 在 GNU 绘图中完成此操作?
谢谢
动画 GIF 是使用set terminal gif animate. 检查help gif详情。下面是一个简单的示例(使用 gnuplot 5.2 测试)。您必须为每一帧制作一个新的绘图。因此,将绘图命令放入do for循环中。您every ::i::i只绘制第ith 行(检查help every)。如果您不知道数据文件的总行数,请执行此操作,stats "YourFile.dat"变量STATS_records会告诉您这个数字。
代码:
### 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
Run Code Online (Sandbox Code Playgroud)
结果:
添加:
这将是非动画版本,例如在wxt终端中。
代码:
### 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
Run Code Online (Sandbox Code Playgroud)
结果:
加法2:
你的意思可能是这样的吗?“半”动画箭头?顺便说一句,正如您所看到的,箭头在终端中看起来完全gif不同wxt。
代码:
### "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
Run Code Online (Sandbox Code Playgroud)
结果: