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
axsrc.scatter(x,y,s,c)
axzoom.scatter(x,y,s,c)
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)
figzoom.canvas.draw()
figsrc.canvas.mpl_connect('button_press_event', onpress)
show()