title: Select n data points from plot
body: <p>I want to select points by clicking om them in a plot and store the point in an array. I want to stop selecting points after n selections, by for example pressing a key. How can I do this? This is what I have so far.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.set_title('click on points')
  
  line, = ax.plot(np.random.rand(100), 'o', picker=5)  # 5 points tolerance
  
  def onpick(event):
      thisline = event.artist
      xdata = thisline.get_xdata()
      ydata = thisline.get_ydata()
      ind = event.ind
      points = tuple(zip(xdata[ind], ydata[ind]))
      print('onpick points:', points)
  
  
  fig.canvas.mpl_connect('pick_event', onpick)
  
  plt.show()
  </code></pre>