In the example found here (and repeated below) everything works perfectly well until I remove ani =
from the line animation.FuncAnimation(fig, animate, interval=20, blit=True, save_count=50)
.
But this bit just assign the animation into a variable which is not used anymore ! It shouldn’t change the behavior ? Why does it ?
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
def animate(i):
line.set_ydata(np.sin(x + i / 50)) # update the data.
return line,
ani = animation.FuncAnimation(fig, animate, interval=20, blit=True, save_count=50)
plt.show()