gpt4 book ai didi

python - 如何将动态pyplot保存为电影文件?

转载 作者:太空狗 更新时间:2023-10-30 02:22:11 26 4
gpt4 key购买 nike

我遇到了这个可以帮助我解决问题的简单示例:

"""
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 界面中显示动画,但我想将此动画保存为某种电影格式,有什么办法吗?

最佳答案

一种方法是将所有步骤保存为图像,然后将它们制作成电影,例如ffmpeg .

关于python - 如何将动态pyplot保存为电影文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12100405/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com