Hi,
we are trying to change from scipy.xplt to matplotlib and
need advice on dynamic plots.
With the examples at the end of this e-mail we get the following
frame rates (PIV, 2.8 GHz, debian sarge, python 2.3, matplotlib 0.64)
FPS
xplt 1000 (mov_sin_xplt.py)
TkAgg 20 (mov_sin_mpl_tkagg.py)
TkAgg2 5 (mov_sin_mpl_tkagg2.py)
gtk 60 (mov_sin_mpl_gtk.py)
gtkAgg 37 (mov_sin_mpl_gtk.py)
We also have a wx version, but the code is really complicated
(any pointers on how to code our example most simply with the wx backend
would be also very much appreciated).
Obviously, our matplotlib implementations run much
slower than scipy.xplt. Do you have any suggestions
on how we could improve the speed of the code?
More generally, our impression is that with matplotlib
the code tends to be more complicated (timers, classes etc.)
than the scipy.xplt version. Maybe there are
better ways to achieve what we want (but we haven't found them yet ;-).
Personally we don't mind too much about using classes, timers and events,
but
we want to replace scipy.xplt in a course on computational physics.
Most of the students have not been exposed to these concepts before,
so we have to avoid that completely.
Our experiences with scipy.xplt were very positive
as it allows a `linear programming style', which is very suitable
for beginners.
Best,
Lars and Arnd
···
###############################################
## mov_sin_xplt.py
from scipy.xplt import *
import time
x = arange(0,2*pi,0.01) # x-array
window(wait=1) # wait for plotting
animate(1) # use blitting
tstart = time.time()
for i in arange(10000):
plg(sin(x+i/100.0),x,marks=0) # plot the function
fma() # blit the offscreen pixmap
print 'FPS:' , 10000/(time.time()-tstart)
###############################################
## mov_sin_mpl_tkagg.py
import matplotlib
matplotlib.use('TkAgg')
matplotlib.interactive(True)
from matplotlib.matlab import *
from Numeric import *
import time
x = arange(0,2*pi,0.01) # x-array
lines = plot(x,sin(x)) # plot the function
axis([0.0,2*pi,-1.0,1.0]) # setup axis
tstart = time.time()
for i in arange(200):
lines[0].set_ydata(sin(x+i/10.0)) # change y-data
draw() # force redraw
print 'FPS:' , 200/(time.time()-tstart)
###############################################
## mov_sin_mpl_tkagg2.py
import matplotlib
matplotlib.use('TkAgg')
matplotlib.interactive(True)
from matplotlib.matlab import *
from Numeric import *
import time
x = arange(0,2*pi,0.01) # x-array
axis([0.0,2*pi,-1.0,1.0]) # setup axis
tstart = time.time()
or i in arange(200):
clf()
plot(x,sin(x+i/10.0))
print 'FPS:' , 200/(time.time()-tstart)
###############################################
## mov_sin_mpl_gtk.py
import matplotlib
matplotlib.use('GTKAgg') # matplotlib.use('GTK')
from matplotlib.matlab import *
from Numeric import *
import gtk
import time
x = arange(0,2*pi,0.01) # x-array
lines = plot(x,sin(x))
axis([0.0,2*pi,-1.0,1.0])
manager = get_current_fig_manager()
tstart = time.time()
def updatefig(*args):
updatefig.count += 1
lines[0].set_ydata(sin(x+updatefig.count/10.0))
manager.canvas.draw()
if updatefig.count>1000:
print 'FPS:' , 1000/(time.time()-tstart)
return gtk.FALSE
return gtk.TRUE
updatefig.count=-1
gtk.idle_add(updatefig)
show()
--
GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail
+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++