from matplotlib import pyplot as plt import numpy as np def handler(event): # -- find closest point to where the mouse click occured d = (event.xdata-X)**2 + (event.ydata-Y)**2 i = d.argmin() # -- re-plot data a.plot(X, Y, '.b-') # -- plot closest point as yellow star a.plot(X[i], Y[i], '*y', markersize=20) # -- update plot plt.draw() return # -- fake data: X, Y = np.arange(10), np.random.rand(10) # -- create figure and axe plt.close('all') f = plt.figure() a = f.add_subplot(111) # -- add "handler" to the figure f.canvas.mpl_connect('button_press_event', handler) # -- initial plot a.plot(X, Y, '.b-')