title: Store mouse click event coordinates with matplotlib
body: <p>I am trying to implement a simple mouse click event in matplotlib. I wish to plot a figure then use the mouse to select the lower and upper limits for integration.
  So far I am able to print the coordinates to screen but not store them for later use in the program. I would also like to exit the connection to the figure after the second mouse click.</p>
  
  <p>Below is the code which currently plots and then prints the coordinates.</p>
  
  <p><strong>My Question(s):</strong></p>
  
  <p>How can I store coordinates from the figure to list? i.e. click = [xpos, ypos]</p>
  
  <p>Is it possible to get two sets of x coordinates in order to do a simple integration over that section of line?</p>
  
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  import matplotlib.pyplot as plt
  
  x = np.arange(-10,10)
  y = x**2
  
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.plot(x,y)
  
  def onclick(event):
      global ix, iy
      ix, iy = event.xdata, event.ydata
      print 'x = %d, y = %d'%(
          ix, iy)
  
      global coords
      coords = [ix, iy]
  
      return coords
  
  
  for i in xrange(0,1):
  
      cid = fig.canvas.mpl_connect('button_press_event', onclick)
  
  
  plt.show()
  </code></pre>