class_docstr: A crosshair cursor like `~matplotlib.widgets.Cursor` with a text showing     the current coordinates.
  
  For the cursor to remain responsive you must keep a reference to it.
  The data of the axis specified as *dataaxis* must be in ascending
  order. Otherwise, the `numpy.searchsorted` call might fail and the text
  disappears. You can satisfy the requirement by sorting the data you plot.
  Usually the data is already sorted (if it was created e.g. using
  `numpy.linspace`), but e.g. scatter plots might cause this problem.
  The cursor sticks to the plotted line.
  
  Parameters
  ----------
  line : `matplotlib.lines.Line2D`
      The plot line from which the data coordinates are displayed.
  
  numberformat : `python format string <https://docs.python.org/3/    library/string.html#formatstrings>`_, optional, default: "{0:.4g};{1:.4g}"
      The displayed text is created by calling *format()* on this string
      with the two coordinates.
  
  offset : (float, float) default: (5, 5)
      The offset in display (pixel) coordinates of the text position
      relative to the cross-hair.
  
  dataaxis : {"x", "y"}, optional, default: "x"
      If "x" is specified, the vertical cursor line sticks to the mouse
      pointer. The horizontal cursor line sticks to *line*
      at that x value. The text shows the data coordinates of *line*
      at the pointed x value. If you specify "y", it works in the opposite
      manner. But: For the "y" value, where the mouse points to, there might
      be multiple matching x values, if the plotted function is not biunique.
      Cursor and text coordinate will always refer to only one x value.
      So if you use the parameter value "y", ensure that your function is
      biunique.
  
  Other Parameters
  ----------------
  textprops : `matplotlib.text` properties as dictionary
      Specifies the appearance of the rendered text object.
  
  **cursorargs : `matplotlib.widgets.Cursor` properties
      Arguments passed to the internal `~matplotlib.widgets.Cursor` instance.
      The `matplotlib.axes.Axes` argument is mandatory! The parameter
      *useblit* can be set to *True* in order to achieve faster rendering.
docstr: Finds the coordinates, which have to be shown in text.
  
  The behaviour depends on the *dataaxis* attribute. Function looks
  up the matching plot coordinate for the given mouse position.
  
  Parameters
  ----------
  xpos : float
      The current x position of the cursor in data coordinates.
      Important if *dataaxis* is set to 'x'.
  ypos : float
      The current y position of the cursor in data coordinates.
      Important if *dataaxis* is set to 'y'.
  
  Returns
  -------
  ret : {2D array-like, None}
      The coordinates which should be displayed.
      *None* is the fallback value.
docstr_tok: ["Finds","the","coordinates",",","which","have","to","be","shown","in","text",".","The","behaviour","depends","on","the","*","dataaxis","*","attribute",".","Function","looks","up","the","matching","plot","coordinate","for","the","given","mouse","position",".","Parameters","--","--","--","--","--","xpos",":","float","The","current","x","position","of","the","cursor","in","data","coordinates",".","Important","if","*","dataaxis","*","is","set","to","'","x","'",".","ypos",":","float","The","current","y","position","of","the","cursor","in","data","coordinates",".","Important","if","*","dataaxis","*","is","set","to","'","y","'",".","Returns","--","--","--","-","ret",":","{","2D","array-like",",","None","}","The","coordinates","which","should","be","displayed",".","*","None","*","is","the","fallback","value","."]
code: def set_position(self, xpos, ypos):
      """
      Finds the coordinates, which have to be shown in text.
  
      The behaviour depends on the *dataaxis* attribute. Function looks
      up the matching plot coordinate for the given mouse position.
  
      Parameters
      ----------
      xpos : float
          The current x position of the cursor in data coordinates.
          Important if *dataaxis* is set to 'x'.
      ypos : float
          The current y position of the cursor in data coordinates.
          Important if *dataaxis* is set to 'y'.
  
      Returns
      -------
      ret : {2D array-like, None}
          The coordinates which should be displayed.
          *None* is the fallback value.
      """
  
      # Get plot line data
      xdata = self.line.get_xdata()
      ydata = self.line.get_ydata()
  
      # The dataaxis attribute decides, in which axis we look up which cursor
      # coordinate.
      if self.dataaxis == "x":
          pos = xpos
          data = xdata
          lim = self.ax.get_xlim()
      elif self.dataaxis == "y":
          pos = ypos
          data = ydata
          lim = self.ax.get_ylim()
      else:
          raise ValueError(
              f"The data axis specifier {self.dataaxis} should "
              f"be 'x' or 'y'"
          )
  
      # If position is valid and in valid plot data range.
      if pos is not None and lim[0] <= pos <= lim[-1]:
          # Find closest x value in sorted x vector.
          # This requires the plotted data to be sorted.
          index = np.searchsorted(data, pos)
          # Return none, if this index is out of range.
          if index < 0 or index >= len(data):
              return None
          # Return plot point as tuple.
          return (xdata[index], ydata[index])
  
      # Return none if there is no good related point for this x position.
      return None
  
file_path: matplotlib/galleries/examples/widgets/annotated_cursor.py
imports: import matplotlib.pyplot
  import numpy
  from matplotlib.backend_bases import MouseEvent
  from matplotlib.widgets import Cursor
label_desc: Use image node_id 3 for calling the AnnotatedCursor obj's underlying member method code with example usage: obj.set_position(xpos, ypos) and returns: None, xdata,  ydata, None