matplotlib animation duration解释说,基本上FuncAnimation中的论元franes定义了它应该动画的帧的总数。但是,当我运行示例代码时,它似乎一直在运行。我预计无花果会在4秒后停止更新,但是没有。是否需要禁用某种循环?谢谢。我在Python 3.7和matplotlib 3.0.3上运行了它
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2,2))
line, = ax.plot([], [], lw=2)
# init func, plot the background of each frame.
def init():
line.set_data([], [])
return line,
def animate(i):
x = np.linspace(0, 2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=200, interval=20, blit=True)
plt.show()
答案 0 :(得分:1)
您的repeat=False
通话中需要FuncAnimation
。
repeat : bool, optional
Controls whether the animation should repeat when the sequence of frames is completed. Defaults to True.
答案 1 :(得分:0)