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

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

问题描述

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

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