首先,由于您的
animate(i)
没有返回任何内容。你需要回去
line,
.其次,您没有使用
i
在里面
动画制作(i)
还有。
下面是一个简单的正弦曲线动画
https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/
:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
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,
changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)
plt.show()
链接中还有其他灵感,可能会进一步帮助您。