Hi, I am writing a small module to easily load images and interact with them. I now face a memory usage +CPU problem, which may in fact be the result of a normal behaviour of matplotlib (but more certainly something I am not doing right), but I really like to be sure here because if confirmed, it would mean that this module is almost not usable for large images...
Below is a (very simplified) example of what I am doing, that script showing a similar behaviour than the real full module. Questions and problems: 1/ when I load the image the first time (first imshow command in the script), I see that, although the amount of data is very small, ipython/matplotlib already uses more than 40 Mb of memory! Is that normal? 2/ When I now use the mouse_move event, it can go up to 150 Mb of memory usage!! Again: is that normal? 3/ When I do successive cycles of connect, disconnect, imshow (reloading the figure), the memory usage seems to grow slightly, but more importantly the capturing event (writing the data intensity on the top right corner of the figure) gets REALLY SLOW.. Try a series of 10 imshow with the same data.. So maybe I should "clean" some structure somewhere to allow a fast interaction, or maybe the code below is rubish. But so far I haven't found a cure, and this is very annoying to say the least. Thanks for any tip on this problem. Eric P.S.: and for the sake of tempering the questions above (certainly caused by my ignorance): matplotlib + numpy is just an amazing combination!!! P.P.S: set up for me is: Suse 10.1 matplotlib version 0.87.7 numerix numpy 1.0.2.dev3491 Python 2.4.2 (#1, May 2 2006, 08:13:46) IPython 0.7.4.svn.r2010 -- An enhanced Interactive Python. ## =============================== ## Below is a small script to illustrate memory and CPU pbs ## It loads some rand data, with coordinates given in xy ## and the mouse event allows to write the intensity of ## the image in the top right corner of the figure ## =============================== import numpy as num import matplotlib as mpl import matplotlib.pylab as plab data = num.random.rand(200,200) xy = [num.arange(0.,20,.1), num.arange(0.,20,.1)] fig = plab.figure() canvas = fig.canvas plab.imshow(data, extent=[0.,20.,0.,20.]) ftext = plab.figtext(0.9,0.9,"") def whichpix_inframe(coord) : indw = num.zeros(2, num.int32) if len(coord) == 2 : indw[0] = num.sort(xy[0]).searchsorted(coord[0]) indw[1] = num.sort(xy[1]).searchsorted(coord[1]) return indw def mouse_move(event) : if event.inaxes : ax = event.inaxes ftext.set_text(str(data[tuple(whichpix_inframe([event.xdata, event.ydata]))])) canvas.draw() id = canvas.mpl_connect('motion_notify_event', mouse_move) ## then we can go on and cycle through the next 3 lines...: it shows the CPU+memory pb getting worse # canvas.mpl_disconnect(id) # plab.imshow(data, extent=[0.,20.,0.,20.]) # id = canvas.mpl_connect('motion_notify_event', mouse_move) ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users