I have a "simple" problem with mpl, but didn't find a way to solve it so
Let's say I have a set of three 2Darrays I would like to :
- load using imshow
- then connect to the mouse click event and add all X and Y coordinates
obtained when clicking
(so each time I click, I'll get xc += event.x for example)
and PAUSE the program until I get a click on the right button of the mouse
- when I click on the right button of the mouse, I want the program to
go on and load the second data array
- ... and continue until all data arrays have been looked at in that way.
So in principle it would look like the script below. But of course this
DOES NOT WORK!!!
So I would welcome any suggestion of how to solve this problem....
import numpy as num
def __init__(self) :
self.xc = 0.
self.yc = 0.
self.stay = 1
def on_click(self, event) :
if event.button == 1:
if event.inaxes is not None:
self.xc += event.xdata
self.yc += event.ydata
elif event.button == 3:
self.stay = 0
data1 = num.random.rand(10,10)
data2 = num.random.rand(10,10)
data3 = num.random.rand(10,10)
alldata = [data1, data2, data3]
for i in range(len(alldata)) :
newoffset = offset()
binding = connect('button_press_event', newoffset.on_click)
while newoffset.stay :
print newoffset.xc, newoffset.yc