【发布时间】:2019-07-07 15:57:12
【问题描述】:
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()
【问题讨论】:
标签: python matplotlib