code: def line_picker(line, mouseevent):
      """
      Find the points within a certain distance from the mouseclick in
      data coords and attach some extra attributes, pickx and picky
      which are the data points that were picked.
      """
      if mouseevent.xdata is None:
          return False, dict()
      xdata = line.get_xdata()
      ydata = line.get_ydata()
      maxd = 0.05
      d = np.sqrt(
          (xdata - mouseevent.xdata) ** 2
          + (ydata - mouseevent.ydata) ** 2
      )
  
      (ind,) = np.nonzero(d <= maxd)
      if len(ind):
          pickx = xdata[ind]
          picky = ydata[ind]
          props = dict(ind=ind, pickx=pickx, picky=picky)
          return True, props
      else:
          return False, dict()
  
file_path: matplotlib/galleries/examples/event_handling/pick_event_demo.py
imports: import matplotlib.pyplot
  import numpy
  from numpy.random import rand
  from matplotlib.image import AxesImage
  from matplotlib.lines import Line2D
  from matplotlib.patches import Rectangle
  from matplotlib.text import Text
label_desc: Use image node_id 2 for calling a global function with example usage: line_picker(line, mouseevent) and returns: False,  dict, True,  props, False,  dict