用gnuplot绘制轨迹 [英] Plotting trajectory with gnuplot

查看:64
本文介绍了用gnuplot绘制轨迹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据文件,其移动点的位置采用以下格式.

I have a datafile with position of a moving point in the following format.

x1  y1
x2  y2 
x3  y3
.
.
.

我希望使用gnuplot中的此数据制作动画轨迹.我该怎么办?

I wish to make an animated trajectory with this data in gnuplot. How can I do that?

我尝试了

do for [i=1:20] {
plot "temp.dat" every ::i using 1 : 2 w p
}

但是它将所有点绘制在单个图像中,而不是动画中.这样做的方式是什么?

But it plots all the points in a single image, not an animation. What is the way of doing this?

推荐答案

虽然我正在编码并被打断……@Ethan的答案已经包含了所有必要的成分,但是我还是通过一些视觉演示演示了我的答案..选中 help gif help stats help ,这些是主要的组件".在下面的示例中,您希望找到想要的东西.

While I was coding and got interrupted... @Ethan's answer already contains all the necessary ingredients, I post my answer nevertheless, with a little visual demo... Check help gif, help stats and help every, these are the main "components". In the following example you hopefully find what you are looking for.

代码:

### trajectory animated
reset session

# create some test data
v = 40
a = 45
g = 9.81
set print $Data
    do for [i=0:86] {
        t = i/10.
        sx(t) = v*cos(a)*t
        sy(t) = v*sin(a)*t - 0.5*g*t**2 
        print sprintf("%.3f %.3f",sx(t),sy(t))
    }
set print

set xrange[0:200]
set yrange[0:80]

set term gif size 400,300 animate delay 5 optimize
set output "Trajectory.gif"

stats $Data nooutput
N = STATS_records
do for [i=0:N-1] {
    plot $Data u 1:2 every ::::i w l notitle, \
         '' u 1:2 every ::i::i w p pt 7 lc rgb "red" notitle
}
set output
### end of code

结果:

这篇关于用gnuplot绘制轨迹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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