animation

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()

The wiki example works fine. I'll follow that model. You mentioned that only the GtkAgg was supported, but it "appears" that the TkAgg has support as well???

Thanks as always,
  Charlie

John Hunter wrote:

···

"Charles" == Charles Moad <cmoad@...209...> writes:

    > 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()

I added the blit method to the tkagg, but I don't know what needs to be done to take the bbox into account. Even as it stands I get 141 fps in animation_blit.py compared to gtk's 350 fps. Whoever is the tk expert, any clue on how to account for the bbox on blit updates?

- Charlie

Charles Moad wrote:

···

The wiki example works fine. I'll follow that model. You mentioned that only the GtkAgg was supported, but it "appears" that the TkAgg has support as well???

Thanks as always,
    Charlie

John Hunter wrote:

    > 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()

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * TechWell - Software Conferences, Training, & Resources
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options