code: def detrend(x, key=None, axis=None):
      """
      Return *x* with its trend removed.
  
      Parameters
      ----------
      x : array or sequence
          Array or sequence containing the data.
  
      key : {'default', 'constant', 'mean', 'linear', 'none'} or function
          The detrending algorithm to use. 'default', 'mean', and 'constant' are
          the same as `detrend_mean`. 'linear' is the same as `detrend_linear`.
          'none' is the same as `detrend_none`. The default is 'mean'. See the
          corresponding functions for more details regarding the algorithms. Can
          also be a function that carries out the detrend operation.
  
      axis : int
          The axis along which to do the detrending.
  
      See Also
      --------
      detrend_mean : Implementation of the 'mean' algorithm.
      detrend_linear : Implementation of the 'linear' algorithm.
      detrend_none : Implementation of the 'none' algorithm.
      """
      if key is None or key in ["constant", "mean", "default"]:
          return detrend(x, key=detrend_mean, axis=axis)
      elif key == "linear":
          return detrend(x, key=detrend_linear, axis=axis)
      elif key == "none":
          return detrend(x, key=detrend_none, axis=axis)
      elif callable(key):
          x = np.asarray(x)
          if axis is not None and axis + 1 > x.ndim:
              raise ValueError(f"axis(={axis}) out of bounds")
          if (axis is None and x.ndim == 0) or (
              not axis and x.ndim == 1
          ):
              return key(x)
          # try to use the 'axis' argument if the function supports it,
          # otherwise use apply_along_axis to do it
          try:
              return key(x, axis=axis)
          except TypeError:
              return np.apply_along_axis(key, axis=axis, arr=x)
      else:
          raise ValueError(
              f"Unknown value for key: {key!r}, must be one of: 'default', "
              f"'constant', 'mean', 'linear', or a function"
          )
  
imports: import functools
  from numbers import Number
  import numpy
  from matplotlib import _api, _docstring, cbook
label_desc: Use image node_id 3 for calling a global function with example usage: detrend(x, key, axis) and returns: detrend, detrend, detrend, key, key, np