import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
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')
def animate(i):
redDot.set_data(i, np.sin(i))
return redDot,
# create animation using the animate() function
myAnimation = animation.FuncAnimation(fig, animate, frames=np.arange(0.0, TWOPI, 0.1), \
interval=10, blit=True, repeat=True)
plt.show()
This is code from https://riptutorial.com/matplotlib/example/23558/basic-animation-with-funcanimation The desired output it shown on that website. It's supposed to show a dot moving across a sine wave. When I run the code I just get a dot at the beginning of the sine wave, without any animation. I've tried it in Spyder and Jupyter with the same result in each. Why isn't this working?
EDIT: Adding "%matplotlib notebook" has fixed it. However now I want to download my animation, and I tried the following
myAnimation.save('dynamic_images.mp4')
But I got the error message "MovieWriter ffmpeg unavailable; trying to use instead." I made sure to install ffmpeg with
pip install ffmpeg
But that hasn't helped. How do I download animations with Jupyter Notebook? I also tried
from IPython.display import HTML
HTML(ani.to_html5_video())
and I get an error again because "Requested MovieWriter (ffmpeg) not available"