Я пытаюсь использовать matplotlib.animation.FuncAnimation для создания пользовательской анимации.Однако функция FuncAnimation, похоже, не выполняет вторую итерацию функции animate.Я приложил простой пример, который я нашел онлайн, который должен работать и рисовать синусоидальную волну.И на моем компьютере, и на сервере Amazon EC2 скрипт вызывает animate и рисует кадр за одну итерацию.Вторая итерация никогда не происходит.Что я не так делаю?
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
# animation function. This is called sequentially
def animate(i):
print("animate invoked")
print(i)
x = np.linspace(0, 2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
return line,
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, frames=np.arange(100), interval=200)
plt.show()
Вывод скрипта:
animate вызывается
0