Python 如何将动态pyplot保存为电影文件?
我遇到了一个简单的例子,可以帮助我解决问题:Python 如何将动态pyplot保存为电影文件?,python,matplotlib,Python,Matplotlib,我遇到了一个简单的例子,可以帮助我解决问题: """ Pyplot animation example. The method shown here is only for very simple, low-performance use. For more demanding applications, look at the animation module and the examples that use it. """ import matplotlib.pyplot as pl
"""
Pyplot animation example.
The method shown here is only for very simple, low-performance
use. For more demanding applications, look at the animation
module and the examples that use it.
"""
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(6)
y = np.arange(5)
z = x * y[:,np.newaxis]
for i in xrange(5):
if i==0:
p = plt.imshow(z)
fig = plt.gcf()
plt.clim() # clamp the color limits
plt.title("Boring slide show")
else:
z = z + 2
p.set_data(z)
print "step", i
plt.pause(0.5)
这将在pyplot界面中显示动画,但我想以某种电影格式保存此动画,有办法吗?一种方法是将所有步骤保存为图像,然后将它们制作成电影,例如。另一种将matplotlib动画保存为视频的方法在本文中进行了说明。它显示了更高级别的解决方案,其中可以将动画指定为随时间变化的绘制函数。此外,您不必处理保存每个帧的问题。谢谢您的链接。我知道matplotlib.animation,但我浪费了一整天的时间试图在其中实现我的问题(不是本例),但没有成功,我需要在今天完成动画,所以我非常绝望,一旦我找到了理解matplotlib.animation用法的方法,我肯定会用正确的方法来做,我觉得它非常不直观。我支持这个建议。matplotlib存储库的主分支中提供了改进电影保存的最新工作。动态编码电影要比保存到图像然后合并它们快得多。