On Wed, Feb 10, 2010 at 12:39 PM, John Jameson <jjame...@altoresearch.com> wrote: > Hi - > I am wondering how to animate using blit and patches. > The code below was modified from one of the examples. > You will see that it shows (and moves) the rectangle just fine, but > the circle never shows up.
Artists must be added to the axes -- when you do line, = ax.plot(...) the Line2D object is added t the Axes. But you never add the circle to the axes. So do cir = CirclePolygon((x_cir, 1), 0.3, animated=True, resolution=6, lw=2) ax.add_patch(cir) and then call ax.draw_artist(cir) when you want to draw it. JDH > best, > Jaron > > > > import gtk, gobject > import matplotlib > matplotlib.use('GTKAgg') #Agg rendering to a GTK canvas (requires PyGTK) > import numpy as np > import matplotlib.pyplot as plt > from pylab import * > from matplotlib.patches import CirclePolygon > > fig = plt.figure(figsize=(14,10)) > ax = fig.add_subplot(111, autoscale_on=False ) > canvas = fig.canvas > > x_start = array([1.0, 2, 2, 1, 1]) > y_start = array([1.0, 1, 2, 2, 1]) > > plt.axis([-1, 7, -0.5, 2.2]) > > def update_line(): > global x, y > print update_line.cnt > if update_line.background is None: > update_line.background = canvas.copy_from_bbox(ax.bbox) > canvas.restore_region(update_line.background) > > x = x_start + 0.012 * update_line.cnt > y = y_start + 0.0001 * update_line.cnt > line, = ax.plot(x, y, animated=True, lw=2) > ax.draw_artist(line) > > x_cir = 1.0 + 0.001*update_line.cnt > cir = CirclePolygon((x_cir, 1), 0.3, animated=True, resolution=6, lw=2 > ) > ax.draw_artist(cir) > > canvas.blit(ax.bbox) > > if update_line.cnt == 10000: > gtk.mainquit() > raise SystemExit > update_line.cnt += 1 > return True > > update_line.cnt = 0 > update_line.background = None > > def start_anim(event): > gobject.idle_add(update_line) > canvas.mpl_disconnect(start_anim.cid) > > start_anim.cid = canvas.mpl_connect('draw_event', start_anim) > > plt.show() > > > > > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users