Hi,
I am trying to do an animation in two axes (subplots) and I can get it to
work so-so if I do it the "wrong way" but when I do it the "right way" I
don't see anything in my second subplot.

The first subplot (ax1) shows a bunch of moving line segments ("sticks") and
the second one (ax2) shows a low resolution (pixellated) view of the first
subplot. The latter (ax2) uses imshow() but when I update it through
setarray() and blit it onto the canvas it doesn't show up (although the
sticks in the ax1 show up fine). However, if I insert the line canvas.draw()
after the ax2 blit it works but it makes the ax1 animation very jittery.

Can someone tell me the correct way to do this?  I'm still a tenderfoot in
Matplotlib ;-(

thanks!
John







class Sticks_animator():
    x_offset = 0.0 



    def __init__(self, n_sticks_tot, n_pixels_horizontal=0,

            n_pixels_vertical=0 ):

.
.
.
.
.

   def reset(self):

        self.background1 = None

        self.background2 = None

        self.start = 1



    def draw_sticks(self):



        if self.start:

            self.poly = []

            for i in range( self.n_sticks_tot):

                x_stick = array([ [self.x1[i], self.y1[i]],

                                  [self.x2[i], self.y2[i]] ] )

                

                self.poly.append( Polygon( x_stick, animated=True,

                                           lw=2, fill=False) )
                self.ax1.add_patch(self.poly[i])

                self.ax1.draw_artist(self.poly[i])
            

        else:

            for i in range( self.n_sticks_tot):

                x_stick = array([ [self.x1[i], self.y1[i]],

                                  [self.x2[i], self.y2[i]] ] )

                self.poly[i].set_xy(x_stick)

                self.ax1.draw_artist(self.poly[i])


    def draw_retina(self):

        if self.start:

            self.img = self.ax2.imshow(self.inten, interpolation='nearest')
        else: 

            self.img.set_array(self.inten)
            

    def step_it(self):
        self.inten, self.n_sticks_tot, self.x1, self.y1, \

                       self.x2, self.y2, done = self.stks.Step_it()
        
# self.stks.Step_it() is finds all the stick coordinates
#   and inten is a NXN array of a pixellated (low res) view

#   of all the sticks

        

if self.background1 is None:

            self.background1 = self.canvas.copy_from_bbox(self.ax1.bbox)

        self.canvas.restore_region(self.background1)

        self.draw_sticks()

        self.canvas.blit(self.ax1.bbox)



        if self.add_retina_view:
            self.draw_retina()

            self.canvas.blit(self.ax2.bbox)

#            self.canvas.draw()   IF I UNCOMMENT THIS IT "WORKS"


        self.start = 0

        

        if done:
            gtk.main_quit()

            raise SystemExit

        return True



    def mainer( self, stks ):
 self.stks = stks 


        if isinteractive():

            ioff()
        def start_anim(event):

            gobject.idle_add( self.step_it )

            self.canvas.mpl_disconnect(start_anim.cid)
            

        start_anim.cid = self.canvas.mpl_connect('draw_event', start_anim)

        plt.show()




------------------------------------------------------------------------------
RSA® Conference 2012
Save $700 by Nov 18
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to