So, I'm trying to write a program that detects a mouse click on the image and saves the position x, y. I used matplotlib and I have work with the basic plot, but when I try to use the same code with the image, I get the following error:
cid = implot.canvas.mpl_connect ('button_press_event', onclick) The AxesImage object does not have a canvas attribute
This is my code:
import matplotlib.pyplot as plt im = plt.imread('image.PNG') implot = plt.imshow(im) def onclick(event): if event.xdata != None and event.ydata != None: print(event.xdata, event.ydata) cid = implot.canvas.mpl_connect('button_press_event', onclick) plt.show()
Let me know if you have any ideas on how to fix this or the best way to achieve my goal. Thank you very much!
source share