gnuplot生成gif动画

最近有个任务需要生成一个动态变化的图,然后突然发现gnuplot竟然可以生成gif动画,当真是应正了博客Gnuplot surprising的子标题:

I always tell myself: "Use your head, then you may find Gnuplot can plot graphics surprising you!"

一个简单的例子

#绘制平移的正弦曲线
set term gif animate
set output "e1.gif"
set xrange [0:4*pi]
set yrange [-1:1]
do for [i=0:40]{
  plot sin(x+i*pi/40) lw 1.5 title sprintf("t=%i",i)
}
set output

效果:

注意:
貌似本用法只在gnuplot 4.6之后的版本中支持

设置图片大小与动画间隔

set term gif size 400,200 #设置图片尺寸,注意该命令需要在下一条命令前,否则不会生成动画
set term gif animate delay 5 #设置动画图片之间延时,单位ms
set output "e2.gif"
set xrange [0:4*pi]
set yrange [-1:1]
do for [i=0:40]{
  plot sin(x+i*pi/40) lw 1.5 title sprintf("t=%i",i)
}
set output

效果:

绘制自己实验的模型表现变化动画

我要观察的是神经网络模型随着训练回合的增长,与目标曲线拟合程度的变化动画。

set term gif size 800,400
set term gif animate delay 20
set output "e3.gif"
set yrange [-50:300]
do for [i=1:50]{
  datafile=sprintf("data/0000017375.%03d.f0cmp.data",i) #我的数据地址
  set label 1 sprintf("epoch=%i",i) at 10,100 font "Arial, 25" #让字体稍微大一点
  plot datafile u 1:2 title 'F0 Answer' w p, datafile u 1:3 title 'F0 Predict' w p pt 1,datafile u 1:4 title 'Word Duration' w p
}
set output

效果:


参考资源:

http://blog.sciencenet.cn/blog-373392-531682.html
http://gnuplot-surprising.blogspot.com/2012/04/new-version-of-gnuplot-makes-iterations.html

posted @ 2014-08-07 11:22  MindProbe  阅读(2929)  评论(0编辑  收藏  举报