I'm trying to use FuncAnimation, but encounter the problem that it stops after displaying only a single frame.
This problem has been posted before on StackOverflow,
Python Matplotlib FuncAnimation only draws one frame
FuncAnimation printing first image only
However, the solution there -- to give a reference to the animation object -- does not do the trick in my case and in both cases leaves blank plots when I plot them.
To give an example, I would expect this code, taken from https://riptutorial.com/matplotlib/example/23558/basic-animation-with-funcanimation to animate a red particle tracing out a sine curve.
However, in my case the red particle gets stuck at t=0. After running the code below, number_of_calls has been increased to 1, and so animate() has only been called once. For reference, I'm using Python 3.6.5.
Any help would be very much appreciated!
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
TWOPI = 2*np.pi
fig, ax = plt.subplots()
t = np.arange(0.0, TWOPI, 0.001)
s = np.sin(t)
l = plt.plot(t, s)
ax = plt.axis([0,TWOPI,-1,1])
redDot, = plt.plot([0], [np.sin(0)], 'ro')
number_of_calls=0
def animate(i):
global number_of_calls
redDot.set_data(i, np.sin(i))
number_of_calls+=1
return redDot,
# create animation using the animate() function
myAnimation = FuncAnimation(fig, animate, frames=np.arange(0.0, TWOPI, 0.1), \
interval=10, blit=True, repeat=True)
plt.show()