I am new here and probably this is super obvious, but I don't get it: I wanna save the clicked coordinates (coords) to work with them aferwards, somehow this doesn't work. I am still on Python 2.7 btw.
thanks in advance!
import matplotlib.pyplot as plt
plt.close('all')
coords=[]
# Simple mouse click function to store coordinates
def onclick(event):
global coords, xi,yi
xi,yi =event.xdata, event.ydata
coords.append((xi,yi))
if len(coords) == 2:
fig.canvas.mpl_disconnect(cid)
plt.close(1)
return coords, xi , yi
x = np.arange(-10,10)
y = x**2
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.plot(x,y)
plt.show(1)
# Call click func
cid = fig.canvas.mpl_connect('button_press_event', onclick)
print coords