Skip to content

Instantly share code, notes, and snippets.

@goretkin
Created June 25, 2012 15:59
Show Gist options
  • Save goretkin/2989424 to your computer and use it in GitHub Desktop.
Save goretkin/2989424 to your computer and use it in GitHub Desktop.
matplotlib animation issue
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib as mpl
ani_fig = plt.figure(None)
ani_ax = ani_fig.gca()
ani_ax.set_xlim(0,1)
ani_ax.set_ylim(0,1)
ani_ax.set_aspect('equal')
color = None
n = 10
def update_frame(i):
for p in ani_ax.patches:
p.remove()
global color
print i
patch = mpl.patches.Circle(xy=(.5,.5+.1*float(i)/n), radius = .1, facecolor=color)
ani_ax.add_patch(patch)
ani_ax.set_title('frame: %d'%(i))
color = 'b'
ani = animation.FuncAnimation(fig=ani_fig,func=update_frame,frames=n)
ani.save('blue.mp4', fps=5, codec='mpeg4', clear_temp=False)
color = 'r'
ani = animation.FuncAnimation(fig=ani_fig,func=update_frame,frames=n/2)
ani.save('red.mp4', fps=5, codec='mpeg4', clear_temp=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment