title: Understanding matplotlib event handling: what are event and mpl_connect?
body: <p>I wanted to make it possible to show values when pressing a dot in my scatterplot. The solution was found here: <a href="https://stackoverflow.com/questions/7908636/possible-to-make-labels-appear-when-hovering-over-a-point-in-matplotlib">Possible to make labels appear when hovering over a point in matplotlib?</a></p>
  
  <p>Solution:</p>
  
  <pre><code>from matplotlib.pyplot import figure, show
  import numpy as npy
  from numpy.random import rand
  
  
  # picking on a scatter plot (matplotlib.collections.RegularPolyCollection)
  
  x, y, c, s = rand(4, 100)
  def onpick3(event):
      ind = event.ind
      print 'onpick3 scatter:', ind, npy.take(x, ind), npy.take(y, ind)
  
  fig = figure()
  ax1 = fig.add_subplot(111)
  col = ax1.scatter(x, y, 100*s, c, picker=True)
  #fig.savefig('pscoll.eps')
  fig.canvas.mpl_connect('pick_event', onpick3)
  
  show()
  </code></pre>
  
  <p>And it solved my problem. But I don't understand how, I've been googling around without any luck. I know how to plot with matplotlib, so that's not where my knowledge is lacking.</p>
  
  <p>One thing I don't understand is the <code>onpick3(event)</code> function. What is this event parameter? Because the function itself is called upon further down without any given arguments: <code>fig.canvas.mpl_connect('pick_event', onpick)</code>.</p>