|
From: Gregory L. <gre...@ff...> - 2004-07-15 11:10:39
|
Hi,
I try to benchmark some modif I did to speed up Agg rendering
(basically, avoid re-creation of an Agg renderer if draw is called
without changing previous fig size and DPI)...
To do so, I changed the dynamic_image demo to use TkAgg (except my fltk
backend, it's the only one working on my workstation for the moment, I
do not have Wx not GTK).
First tests shows no improvement :-(, but in fact I can not reproduce
the speed mentioned when you discussed this demo (4 FPS or 10 FPS), only
got 0.9 FPS.
I thus tryed to check why I got such slow animation, and the results are
as follow (I use the current CVS matplotlib, with numarray):
Example with no drawing (manager.canvas.draw commented out in the
updatefig method) : stabilize around 50 FPS, this is the best we can
hope using numarray which is, I think, the only limitting factor in this
case)...
Example with call to tkagg.blit but no Agg canvas drawing (done
replacing the draw method in FigureCanvasTkAgg, see below * ): stabilize
around 19 FPS
* old draw:
def draw(self):
FigureCanvasAgg.draw(self)
tkagg.blit(self._tkphoto,self.renderer._renderer, 2)
self._master.update_idletasks()
new version:
def draw(self):
try:
tkagg.blit(self._tkphoto,self.renderer._renderer, 2)
except:
FigureCanvasAgg.draw(self)
tkagg.blit(self._tkphoto,self.renderer._renderer, 2)
self._master.update_idletasks()
Example with Agg canvas drawing + blitting: (normal TkAgg backend):
stabilize around 1 FPS
It seems thus that Agg drawing is the main limiting factor here, all
the tricks to avoid using strings (or reallocating Agg renderer, for
that matter) are not too usefull...
What I do not understand is why I got such low values, compared to the 4
or 10 FPS: I guess, given the impact of Agg drawing, all the *Agg
backends should have about the same speed...Is there something I miss
here?
My workstation is not current top of class, but it's a PIV 2.3 GHz, so
certainly not slow either...I do not think the graphic subsystem is at
fault, cause except for a mistake of my part, blit only test shows that
Agg is really the origin of the poor FPS...
Any idea about this?
Thanks,
Best regards,
Greg.
----
Dynamic_image_tkagg.py
----
#!/usr/bin/env python
"""
An animated image
"""
import sys, time, os, gc
from matplotlib import rcParams
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.matlab import *
import Tkinter as Tk
fig = figure(1)
a = subplot(111)
x = arange(120.0)*2*pi/120.0
x = resize(x, (100,120))
y = arange(100.0)*2*pi/100.0
y = resize(y, (120,100))
y = transpose(y)
z = sin(x) + cos(y)
im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest')
manager = get_current_fig_manager()
cnt = 0
tstart = time.time()
class loop:
def __init__(self, master):
self.master = master
self.updatefig() # start updating
def updatefig(self):
global x, y, cnt, start
x += pi/15
y += pi/20
z = sin(x) + cos(y)
im.set_array(z)
manager.canvas.draw()
cnt += 1
if not cnt%20:
print 'FPS', cnt/(time.time() - tstart)
self.master.after(1, self.updatefig)
cnt = 0
loop(manager.canvas._tkcanvas)
show()
|