Hello All,
I'm looking for the most efficient way to perform 2D plot animations.

I've been experimenting with the animation examples from the Matplotlib
cookbook.  More specifically I'm using a version of "Animating selected plot
elements"  that has been modified to work with wxWidgets.  I want to do the
same type of thing but with 2D plots (i.e. imshow).


When I try  ax.draw_artist(im) where "im" is the AxesImage returned from the
initial call to imshow I get an AssertionError for self._cachedRenderer is
not None.


What am I doing wrong?
Thanks
Greg


Here is my hacked up version of the example.
<code>
# The number of blits() to make before exiting
NBLITS = 1000

import matplotlib
matplotlib.use('WXAgg')
matplotlib.rcParams['toolbar'] = None

import wx
import sys
import pylab as p
import matplotlib.numerix as nx
import time

# allow the user to disable the WXAgg accelerator from the command line
if '--no-accel' in sys.argv:
   import matplotlib.backends.backend_wxagg
   matplotlib.backends.backend_wxagg._use_accelerator(False)

ax = p.subplot(111)
canvas = ax.figure.canvas

p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
p.grid() # to ensure proper background restore

# create the initial line
appx = 10.0
appy = 3.8
delta = 0.125
x = p.arange(-appx/2.0, appx/2.0, delta)
y = p.arange(-appy/2.0, appy/2.0, delta)
X, Y = p.meshgrid(x, y)
#     bivariate_normal(X, Y,sigmax,sigmay,mux,muy)
Z = p.bivariate_normal(X, Y, 0.9, 0.7, 4.1, -0.15)

im = p.imshow(Z,cmap=p.cm.hot)

# for profiling
tstart = time.time()
blit_time = 0.0

def update_line(*args):
   global blit_time

   if update_line.background is None:
       update_line.background = canvas.copy_from_bbox(ax.bbox)

   # restore the clean slate background
   canvas.restore_region(update_line.background)
   # update the data
   im.set_data(p.bivariate_normal(X,Y,
                                  0.9,0.7,
                                  4.1+p.sin(update_line.cnt/20.0),
                                  -0.15+p.cos(update_line.cnt/10.0)))
   # just draw the animated artist
   ax.draw_artist(im)
   # just redraw the axes rectangle

   t = time.time()
   canvas.blit(ax.bbox)
   blit_time += time.time() - t

   if update_line.cnt == NBLITS:
       # print the timing info and quit
       frame_time = time.time() - tstart
       print '%d frames: %.2f seconds' % (NBLITS, frame_time)
       print '%d blits:  %.2f seconds' % (NBLITS, blit_time)
       print
       print 'FPS: %.2f' % (NBLITS/frame_time)
       if blit_time > 0:
           print 'BPS: %.2f' % (NBLITS/blit_time)
       global timer
       timer.Stop()

   update_line.cnt += 1



update_line.cnt = 0
update_line.background = None
TIMER_ID=100
panel = wx.GetApp()
global timer
timer = wx.Timer(panel,TIMER_ID)
timer.Start(10)
wx.EVT_TIMER(panel,TIMER_ID, update_line)
update_line()
p.show()

</code>
--
Linux.  Because rebooting is for adding hardware.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to