I would like to display an image in python and allow the user to click on a specific pixel. I then want to use the x and y coordinates to perform further calculations.
So far, I've been using the event picker:
def onpick1(event):
artist = event.artist
if isinstance(artist, AxesImage):
mouseevent = event.mouseevent
x = mouseevent.xdata
y = mouseevent.ydata
print x,y
xaxis = frame.shape[1]
yaxis = frame.shape[0]
fig = plt.figure(figsize=(6,9))
ax = fig.add_subplot(111)
line, = [ax.imshow(frame[::-1,:], cmap='jet', extent=(0,xaxis,0,yaxis), picker=5)]
fig.canvas.mpl_connect('pick_event', onpick1)
plt.show()
Now I would really like the function onpick1()
to return x and y
so I can use it after plt.show()
to perform further calculations.
Any suggestions?