i am trying to make the simplest matplotlib animation, using animation.FuncAnimation
. I dont care about efficiency. i do not want to keep track of the plotted lines and update their data (in my desired application this would be annoying), i simply want to erase the plot before animating every frame. i thought somthing like this should work, but its not..
import matplotlib.animation as animation
fig = Figure()
def updatefig(i):
clf()
p = plot(rand(100))
draw()
anim = animation.FuncAnimation(fig, updatefig, range(10))
At least this seems to work:
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
def updatefig(i):
fig.clear()
p = plt.plot(np.random.random(100))
plt.draw()
anim = animation.FuncAnimation(fig, updatefig, 10)
anim.save("/tmp/test.mp4", fps=1)
The issue with the original code is Figure
written with a capital F (should be figure
).
Otherwise, I would suggest not to use the pylab
style "everything in the same namespace" approach with matplotlib
. Also, using the object-oriented interface instead of plt.draw
, plt.plot
, etc. will save a lot of trouble later on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With