|
From: Auré G. <aur...@ya...> - 2009-09-04 09:18:50
|
Dear all, I recently cried for help (see below) but sadly didn't get any answer... This problem is really a bottleneck for me and if I must find a solution... Can anyone PLEAAAAAAAAASE point me in the right direction ? I recently bumped into a problem while trying to display imshow images (2048x2048 pix) in a GUI based on TkAgg (matplotib0.91.2, python 2..4..4, numpy1.0.4). In brief, building the image with imshow is Ok, but the call to show() or draw() takes about 1.2 s on my system (XP, 2.8Ghz, 2Go ram). After reading a lot of posts and trying out a few things, I turned to the Animation_blit_tk.py example and modified it accordingly (code attached below). In the end, the display is still not much faster using this method (still in the order of 1.2 s as indicated by the result below). Could any one tel me whether I'm doing something wrong ? As far as I understand, at least in my Tk GUI, the limiting step using the ImageTk.FigureCanvasTkAgg is the call to draw() or draw_artist(). I read some comments from John regarding TkAgg being slow in some cases but couldn't find a definite answer. Any hint would be much appreciated.... Cheers, Aure -------- # For detailed comments on animation and the techniqes used here, see # the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations import matplotlib matplotlib.use('TkAgg') import sys import pylab as p #import matplotlib.numerix as nx import time from FileUtils10 import fileHandling # for profiling tstart = time.time() tprevious = time.time() fnamelist = ['fname1','fname2','fname3'] ax = p.subplot(111) canvas = ax.figure.canvas print 't1 ',time.time()-tprevious tprevious = time.time() # create the initial line dataarr = fileHandling(fnamelist[0]).readSpecial() #print dataarr.dtype => numpy dtype uint16 #dataarr = dataarr.astype('uint8') print 't2 ',time.time()-tprevious tprevious = time.time() image = p.imshow(dataarr, animated=True) print 't3 ',time.time()-tprevious tprevious = time.time() def run(*args): tprevious = time.time() background = canvas.copy_from_bbox(ax.bbox) print 't4 ',time.time()-tprevious tprevious = time.time() while 1: #print fnamelist[run.cnt] # restore the clean slate background canvas.restore_region(background) print 't5 ',time.time()-tprevious tprevious = time.time() # update the data dataarr = fileHandling(fnamelist[run.cnt]).readSpecial() print 't6 ',time.time()-tprevious tprevious = time.time() image.set_data(dataarr) print 't7 ',time.time()-tprevious tprevious = time.time() # just draw the animated artist ax.draw_artist(image) print 't8 ',time.time()-tprevious tprevious = time.time() # just redraw the axes rectangle canvas.blit(ax.bbox) print 't9 ',time.time()-tprevious tprevious = time.time() if fnamelist[run.cnt] == fnamelist[-1]: # print the timing info and quit print 'total time:' , time.time()-tstart print 'FPS:' , 1000./(time.time()-tstart) p.close('all') sys.exit() run.cnt += 1 run.cnt = 0 p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs p.grid() # to ensure proper background restore manager = p.get_current_fig_manager() manager.window.after(100, run) p.show() ==== Results in: t1 0.858999967575 t2 0.0320000648499 t3 1.31299996376 t4 0.0 t5 0.0 t6 0.0310001373291 t7 0.0 t8 1.18700003624 t9 0.0160000324249 t5 0.0 t6 0.0469999313354 t7 0.0 t8 1.17200016975 t9 0.0149998664856 t5 0.0 t6 0.047000169754 t7 0.0 t8 1.21899986267 t9 0.0 t5 0.0 t6 0.0460000038147 t7 0.0 t8 1.17199993134 t9 0.0 t5 0.0 t6 0.0469999313354 t7 0.0 t8 1.18700003624 t9 0.0160000324249 total time: 8.75 FPS: 114.285714286 |