I just try to understand how the animation with matplotlib works. And for this I looked up examples and did a copy paste just to let them run and to understand it.
Unfortunately, even the examples from the matplotlib site only show a empty graph (e.g. https://matplotlib.org/examples/animation/animate_decay.html).
Axes, grid, background - everthing is there, just no graph or animation.
I used e.g. this code from the site 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
# First set up the figure, the axis, and the plot element we want to animate
fig5 = plt.figure(5, figsize=(15,15))
ax5 = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, =ax5.plot([], [], lw=2)
# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,
# animation function. This is called sequentially
def animate(i):
x = np.linspace(0, 2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
print(x,y)
return line,
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig5, animate, init_func=init,
frames=200, interval=200, blit=True)
plt.show()
edit: I don't know what I am doing wrong but none of the solution or code example given here Animation in iPython notebook works.
What works is this:
from matplotlib import rc, animation
rc('animation', html='html5')
and then using
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=N, interval=20, blit=True)
anim
This produces a short 9 sec long video that runs and runs and repeats itself until I press the stop button.