Hi,
thanks for this useful and quick answer. I am (always) using GTKAgg
(hope it is a good choice). I understand the 40 Mb part then, but not
the 150-200 Mb... (this happens when I move the cursor within the figure
window only and things get worse when I reload the data with a new imshow).
Two things from what you say:
* first : should I do something before redoing another imshow? (when I
cycle many times through the 3 commands, connect, disconnect, imshow,
the mouse event updating gets really slow, and in fact it seems only the
"imshow" really makes things worse..). Maybe I need to "flush" the old
data/image/imshow ?
* second: I tried to understand what you mentioned in your email about
the blit thing. I understand the "principle", reading the wiki, and
going into mpl examples, but I didn"t manage to implement it in practice
(see my pathetic attempt below). I guess the main reason is that I am
not sure what should be the "background" in the case of a figtext...
(not ax.bbox I guess but then what?)
Any help is welcome (or a hint, since doing it myself is I guess the
best way to learn ...)
thanks again
Eric
#===================================================
# This script is not working... something I didn't understand in
blitting....
#===================================================
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
im = plab.imshow(data, extent=[0.,20.,0.,20.])
ftext = plab.figtext(0.9,0.9,"", animated=True)
ax = plab.gca()
background = canvas.copy_from_bbox(ax.bbox)
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 :
canvas.restore_region(background)
ftext.set_text(str(data[tuple(whichpix_inframe([event.xdata,
event.ydata]))]))
ax.draw_artist(ftext)
canvas.blit(ax.bbox)
# canvas.draw()
id = canvas.mpl_connect('motion_notify_event', mouse_move)
canvas.mpl_disconnect(id)
John Hunter wrote:
> Eric> 2/ When I now use the mouse_move event, it can go up to 150
> Eric> Mb of memory usage!! Again: is that normal?
>
> In your example code below, I notice you are drawing on every mouse
> motion. I believe there is a Tkinter specific leak in TkAgg if memory
> serves, but it's outside of mpl. What backend are you using? Does
> the problem go away with a different backend?
...
> The basic idea is to capture the background as a pixel buffer,
> identify the rectangle region you want to draw the text into, draw the
> background, update the text, redraw only the text rectangle etc....
> See
>
> http://www.scipy.org/Cookbook/Matplotlib/Animation
-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users