python中使用赛璐珞的动画



我正在尝试这个页面上的第一个简单动画。我显然是制作动画的初学者。我粘贴下面的代码。

from matplotlib import pyplot as plt
from celluloid import Camera
fig = plt.figure()
camera = Camera(fig)
for i in range(10):
plt.plot([i] * 10)
camera.snap()
animation = camera.animate()

它给了我以下错误。

Animation was deleted without rendering anything. This is most likely unintended. To prevent deletion, assign the Animation to a variable that exists for as long as you need the Animation.

据我所见,animate((已经被指定了一个名称。有人能帮我解决这个问题吗?

为了避免这个错误(实际上只是UserWarning(,您必须显示或保存动画。在代码的底部:

from matplotlib import pyplot as plt
from celluloid import Camera
fig = plt.figure()
camera = Camera(fig)
for i in range(10):
plt.plot([i] * 10)
camera.snap()
animation = camera.animate()
plt.show()
# OR
animation.save('test.mp4')

最新更新