我找了其他类似的问题,但没有解决我的问题。下面是在matplotlib中生成gif图像形式的动画的简单代码:
import numpy as np
import matplotlib.pylab as plt
import matplotlib.animation as anm
fig = plt.figure()
def draw(i):
x = np.linspace(0, 5, num = 1000)
y = np.sin(x-i*0.1)
plt.clf()
plt.plot(x, y, 'r-')
anim = anm.FuncAnimation(fig, draw, frames = 10, interval = 500, repeat = False)
anim.save('test.gif', fps = 1, writer = 'imagemagick')
这将生成我想要的动画,但是一旦我打开最终图像(使用eog),它就会不断重复。因为我将在演示中演示动画,所以我希望它在显示一次之后停止。正如您所注意到的,我在FuncAnimation中添加了repeat = False
,但这并没有停止重复图像。我的代码怎么了?在
提前谢谢
我解决这个问题的办法是从imagemagick变成pillow作家。在
尝试以下操作:
在我看来,图像的质量比imagemagick差一点,但这是一个更简单、更快的解决方案。在
相关问题 更多 >
编程相关推荐