MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / detrend

Function detrend

lib/matplotlib/mlab.py:81–127  ·  view source on GitHub ↗

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

(x, key=None, axis=None)

Source from the content-addressed store, hash-verified

79
80
81def detrend(x, key=None, axis=None):
82 """
83 Return *x* with its trend removed.
84
85 Parameters
86 ----------
87 x : array or sequence
88 Array or sequence containing the data.
89
90 key : {'default', 'constant', 'mean', 'linear', 'none'} or function
91 The detrending algorithm to use. 'default', 'mean', and 'constant' are
92 the same as `detrend_mean`. 'linear' is the same as `detrend_linear`.
93 'none' is the same as `detrend_none`. The default is 'mean'. See the
94 corresponding functions for more details regarding the algorithms. Can
95 also be a function that carries out the detrend operation.
96
97 axis : int
98 The axis along which to do the detrending.
99
100 See Also
101 --------
102 detrend_mean : Implementation of the 'mean' algorithm.
103 detrend_linear : Implementation of the 'linear' algorithm.
104 detrend_none : Implementation of the 'none' algorithm.
105 """
106 if key is None or key in ['constant', 'mean', 'default']:
107 return detrend(x, key=detrend_mean, axis=axis)
108 elif key == 'linear':
109 return detrend(x, key=detrend_linear, axis=axis)
110 elif key == 'none':
111 return detrend(x, key=detrend_none, axis=axis)
112 elif callable(key):
113 x = np.asarray(x)
114 if axis is not None and axis + 1 > x.ndim:
115 raise ValueError(f'axis(={axis}) out of bounds')
116 if (axis is None and x.ndim == 0) or (not axis and x.ndim == 1):
117 return key(x)
118 # try to use the 'axis' argument if the function supports it,
119 # otherwise use apply_along_axis to do it
120 try:
121 return key(x, axis=axis)
122 except TypeError:
123 return np.apply_along_axis(key, axis=axis, arr=x)
124 else:
125 raise ValueError(
126 f"Unknown value for key: {key!r}, must be one of: 'default', "
127 f"'constant', 'mean', 'linear', or a function")
128
129
130def detrend_mean(x, axis=None):

Callers 2

_spectral_helperFunction · 0.85
xcorrMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…