Agg animation issue

Correction, this is Agg specific. Not limited to Tk.

···

On 12/14/05, Charlie Moad <cwmoad@...287...> wrote:

Best shown with this simple example, the top subplot does not clear
with the call to restore_region. Any clues???

-------------------------------------------------------------
import matplotlib
matplotlib.use('TkAgg')

from pylab import *
ion()

ax1 = subplot(211, xlim=(0,1), ylim=(0,1))
ax2 = subplot(212, xlim=(0,1), ylim=(0,1))
canvas = ax1.figure.canvas

draw()
ax1bg = canvas.copy_from_bbox(ax1.bbox)
ax2bg = canvas.copy_from_bbox(ax2.bbox)
scat1 = None
scat2 = None

def animate(event):
    global ax1bg, ax2bg, scat1, scat2, canvas

    for i in xrange(150):
        print i
        x, y = rand(2,1)
        if scat1 in ax1.collections: ax1.collections.remove(scat1)
        if scat2 in ax2.collections: ax2.collections.remove(scat2)
        scat1 = ax1.scatter(x, y, animated=True)
        scat2 = ax2.scatter(x, y, animated=True)

        canvas.restore_region(ax1bg)
        canvas.restore_region(ax2bg)

        ax1.draw_artist(scat1)
        ax2.draw_artist(scat2)

        canvas.blit(ax1.bbox)
        canvas.blit(ax2.bbox)

ax1.figure.canvas.mpl_connect('draw_event', animate)

show()
-------------------------------------------------------------

Another observation/example. Depending on the order of the axes, the
last one is the only one that acts correctly. So I don't think it is
a coord issue.

···

-------------------------------------------------------------
import matplotlib

from pylab import *
ion()

axs = [subplot(221+i, xlim=(0,1), ylim=(0,1)) for i in xrange(4)]
canvas = gcf().canvas

draw()
bgs = [canvas.copy_from_bbox(ax.bbox) for ax in axs]
scats = [None for ax in axs]

def animate(event):
   global canvas, axs, bgs, scats

   order = [3,0,2,1]

   for i in xrange(150):
       print i
       x, y = rand(2,1)

       for i in order:
          if scats[i] in axs[i].collections: axs[i].collections.remove(scats[i])

       for i in order:
          scats[i] = axs[i].scatter(x, y, animated=True)

       for i in order:
          canvas.restore_region(bgs[i])

       for i in order:
          axs[i].draw_artist(scats[i])

       for i in order:
          canvas.blit(axs[i].bbox)

canvas.mpl_connect('draw_event', animate)

show()
-------------------------------------------------------------

On 12/14/05, Charlie Moad <cwmoad@...287...> wrote:

Correction, this is Agg specific. Not limited to Tk.

On 12/14/05, Charlie Moad <cwmoad@...287...> wrote:
> Best shown with this simple example, the top subplot does not clear
> with the call to restore_region. Any clues???
>
> -------------------------------------------------------------
> import matplotlib
> matplotlib.use('TkAgg')
>
> from pylab import *
> ion()
>
> ax1 = subplot(211, xlim=(0,1), ylim=(0,1))
> ax2 = subplot(212, xlim=(0,1), ylim=(0,1))
> canvas = ax1.figure.canvas
>
> draw()
> ax1bg = canvas.copy_from_bbox(ax1.bbox)
> ax2bg = canvas.copy_from_bbox(ax2.bbox)
> scat1 = None
> scat2 = None
>
> def animate(event):
> global ax1bg, ax2bg, scat1, scat2, canvas
>
> for i in xrange(150):
> print i
> x, y = rand(2,1)
> if scat1 in ax1.collections: ax1.collections.remove(scat1)
> if scat2 in ax2.collections: ax2.collections.remove(scat2)
> scat1 = ax1.scatter(x, y, animated=True)
> scat2 = ax2.scatter(x, y, animated=True)
>
> canvas.restore_region(ax1bg)
> canvas.restore_region(ax2bg)
>
> ax1.draw_artist(scat1)
> ax2.draw_artist(scat2)
>
> canvas.blit(ax1.bbox)
> canvas.blit(ax2.bbox)
>
> ax1.figure.canvas.mpl_connect('draw_event', animate)
>
> show()
> -------------------------------------------------------------
>