Several windows and events

I am using matplotlib to display an image, then click on

    > the image to get the x,y center of an object in that
    > image. Using this x,y position I would like to display a
    > zoomed in version of the image in another window. I am
    > however confused on how to generate the second window and
    > how to deal with the fact that I now want the button click
    > in window 2 to another event function.

Something like this?

from pylab import figure, show, nx
figsrc = figure()
figzoom = figure()

axsrc = figsrc.add_subplot(111, xlim=(0,1), ylim=(0,1), autoscale_on=False)
axzoom = figzoom.add_subplot(111, xlim=(0.45,0.55), ylim=(0.4,.6), autoscale_on=False)
axsrc.set_title('Click to zoom')
axzoom.set_title('zoom window')
x,y,s,c = nx.mlab.rand(4,200)
s *= 200


def onpress(event):
    if event.button!=1: return
    x,y = event.xdata, event.ydata
    axzoom.set_xlim(x-0.1, x+0.1)
    axzoom.set_ylim(y-0.1, y+0.1)

figsrc.canvas.mpl_connect('button_press_event', onpress)

Thanks for the solution. That gives me a good starting point

for further development. However, now I have a follow up

question. Is there a way to return the x and y positions of the

button click from the event (out to the main program I mean).




"Any intelligent fool can make things bigger,

more complex, and more violent. It takes a

touch of genius – and a lot of courage –

to move in the opposite direction"

– Albert Einstein