title: Detecting mouse event in an image with matplotlib
body: <p>So I'm trying write a program that detects a mouse click on an image and saves the x,y position. I've been using matplotlib and I have it working with a basic plot, but when I try to use the same code with an image, I get the following error: </p>
  
  <blockquote>
    <p>cid = implot.canvas.mpl_connect('button_press_event', onclick)
    'AxesImage' object has no attribute 'canvas'</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><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()
  </code></pre>
  
  <p>Let me know if you have any ideas on how to fix this or a better way to achieve my goal. Thanks so much!</p>