I have some lines of code that I use with spyder (using matplotlib) that allow me to save coordinates which are double-clicked. For some reason I don't understand the same code does not work in Jupyter Notebook.
coords = []
class onclick:
""" Saves the coordinates of the left-double-clicked points and finishes with right-double-click """
def __init__(self):
self.cid = fig.canvas.mpl_connect('button_press_event', self)
def __call__(self, event):
global ix, iy
global coords
if event.dblclick:
if event.button==1:
ix, iy = event.xdata, event.ydata
print ('Coordinate clicked: %.3f, %.3f'%(ix, iy))
coords.append((ix, iy))
if event.button==3:
fig.canvas.mpl_disconnect(self.cid)
print("Clicked points saved in 'coords'")
return
cid = onclick()
Any way to make this work in Jupyter Notebook?
(Don't know if this is relevant but in Jupyter Notebook I'm using %matplotlib notebook to be able to zoom in)