Matplotlib动画 - 如何将它们导出到的格式在presentation使用? [英] Matplotlib animations - how to export them to a format to use in a presentation?

查看:209
本文介绍了Matplotlib动画 - 如何将它们导出到的格式在presentation使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

于是,我学会了如何使可爱的小动画在matplotlib。例如,这

So, I learned how to make cute little animations in matplotlib. For example, this:

import numpy as np
import matplotlib
import matplotlib.pyplot as plt

plt.ion()

fig = plt.figure() 
ax  = fig.add_subplot(111) 

ax.set_xlim(0, 1)
ax.set_ylim(-2,2)

dt = 0.01
q  = 0.01
t = np.arange(0,1,dt)
x = np.sin(2*np.pi*t)
line, = ax.plot(t,x, '-')
fig.canvas.draw()
for i in xrange(100):
    x = (1-q) * x + q* np.random.normal(size = len(t))
    line.set_ydata(x)
    fig.canvas.draw()

这工作,这是非常好的。但如何我用这个拍电影我可以显示,例如,在PDF presentation?我试着做 fig.savefig(test.gif),但有表明matplotlib不出口的GIF错误消息。

This works and it's very nice. But how I use this to make a movie I can display, for example, in a pdf presentation? I tried to do fig.savefig("test.gif") but there's an error message indicating that matplotlib doesn't export gifs.

是否有这样做而不求助于外部工具(如作出了很多PNG的和一起缝合他们)?的方法

Is there a way of doing this without resorting to external tools (like making a lot of png's and stitching them together)?

推荐答案

在短,无有是除了使用外部工具没有其他办法。有一个在1.1.0一个新的模块,可以帮助你做动画,然后将其保存为MPEG4格式。它使用外部工具来自动完成这个转换,从许多帧到一个单一的电影。您可以使用让您的GIF ImageMagick的的转换或使用的 ffmpeg的男人codeR ,这是由新提供的两种选择动画模块。

In short, no there is no other way besides using an external tool. There is a new module in 1.1.0 that helps you do animations and save them to mpeg4 format. It uses an external tool to automatically do this conversion, from many frames to a single movie. You can make your gif using imagemagick's convert or use ffmpeg or mencoder, which are the two options provided by the new animation module.

这篇关于Matplotlib动画 - 如何将它们导出到的格式在presentation使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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