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).
Sure -- just use a class to store the coord data, and implement the
__call__ method so it can be used as a callback
class Coords:
def __init__(self):
self.x, self.y = None, None
def __str__(self):
return 'x=%s, y=%s'%(self.x, self.y)
def __call__(self, event):
if event.button!=1: return
x,y = event.xdata, event.ydata
if x is not None: axzoom.set_xlim(x-0.05, x+0.05)
if y is not None: axzoom.set_ylim(y-0.05, y+0.05)
figzoom.canvas.draw()
self.x, self.y = x, y
coords = Coords()
figsrc.canvas.mpl_connect('button_press_event', coords)
Then you can use coords.x and coords.y wherever you want...
JDH