class_docstr: A cross-hair cursor that snaps to the data point of a line, which is
  closest to the *x* position of the cursor.
  
  For simplicity, this assumes that *x* values of the data are sorted.
class_docstr_tok: ["A","cross-hair","cursor","that","snaps","to","the","data","point","of","a","line",",","which","is","closest","to","the","*","x","*","position","of","the","cursor",".","For","simplicity",",","this","assumes","that","*","x","*","values","of","the","data","are","sorted","."]
code: def on_mouse_move(self, event):
      if not event.inaxes:
          self._last_index = None
          need_redraw = self.set_cross_hair_visible(False)
          if need_redraw:
              self.ax.figure.canvas.draw()
      else:
          self.set_cross_hair_visible(True)
          x, y = event.xdata, event.ydata
          index = min(np.searchsorted(self.x, x), len(self.x) - 1)
          if index == self._last_index:
              return  # still on the same data point. Nothing to do.
          self._last_index = index
          x = self.x[index]
          y = self.y[index]
          # update the line positions
          self.horizontal_line.set_ydata([y])
          self.vertical_line.set_xdata([x])
          self.text.set_text(f"x={x:1.2f}, y={y:1.2f}")
          self.ax.figure.canvas.draw()
  
file_path: matplotlib/galleries/examples/event_handling/cursor_demo.py
imports: import matplotlib.pyplot
  import numpy
  from matplotlib.backend_bases import MouseEvent
label_desc: Use image node_id 3 for calling the SnappingCursor obj's underlying member method code with example usage: obj.on_mouse_move(event) without return types