example/animation_blit.py works fine on my laptop, but
> for some reason not obvious to me it is not working on my
> desktop. Here is the error:
> Traceback (most recent call last): File
> "animation_blit.py", line 30, in update_line
> ax.draw_artist(line) File
> "/usr/local/lib/python2.4/site-packages/matplotlib/axes.py",
> line 1336, in draw_artist assert self._cachedRenderer is
> not None AssertionError
> Both machines are up-to-date with cvs. Any clues?
The only way to get this error is if you call draw_artist before
draw. It could have something to do with the order of the calls in
the gtk idle machinery.
Try the following which connects to the new "draw_event" to block
animation until after draw and background storage
# For detailed comments on animation and the techniqes used here, see
# the wiki entry
# http://www.scipy.org/wikis/topical_software/MatplotlibAnimation
import sys
import gtk, gobject
import pylab as p
import matplotlib.numerix as nx
import time
ax = p.subplot(111)
canvas = ax.figure.canvas
# for profiling
tstart = time.time()
# create the initial line
x = nx.arange(0,2*nx.pi,0.01)
line, = p.plot(x, nx.sin(x), animated=True)
# save the clean slate background -- everything but the animated line
# is drawn and saved in the pixel buffer background
background = None
def snap_background(self):
global background
background = canvas.copy_from_bbox(ax.bbox)
p.connect('draw_event', snap_background)
def update_line(*args):
if background is None: return True
# restore the clean slate background
canvas.restore_region(background)
# update the data
line.set_ydata(nx.sin(x+update_line.cnt/10.0))
# just draw the animated artist
ax.draw_artist(line)
# just redraw the axes rectangle
canvas.blit(ax.bbox)
if update_line.cnt==50:
# print the timing info and quit
print 'FPS:' , 200/(time.time()-tstart)
sys.exit()
update_line.cnt += 1
return True
update_line.cnt = 0
gobject.idle_add(update_line)
p.show()