gnuplot 动画二维矢量场 [英] gnuplot animation 2D vector fields

查看:51
本文介绍了gnuplot 动画二维矢量场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 gnuplot 为二维矢量设置动画.我想显示一行,即一次一个向量.

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 测试).您必须为每一帧制作一个新图.因此,将您的绘图命令放入 do for 循环中.使用 every ::i::i 您只绘制 i th 行(检查 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 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.

代码:

### 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:

你的意思可能是这样的吗?半"动画箭头?顺便说一下,正如您所看到的,gifwxt 终端中的箭头看起来完全不同.

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 动画二维矢量场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆