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

Method xcorr

lib/matplotlib/axes/_axes.py:2025–2133  ·  view source on GitHub ↗

r""" Plot the cross correlation between *x* and *y*. The correlation with lag k is defined as :math:`\sum_n x[n+k] \cdot y^*[n]`, where :math:`y^*` is the complex conjugate of :math:`y`. Parameters ---------- x, y : array-like of length n

(self, x, y, normed=True, detrend=mlab.detrend_none,
              usevlines=True, maxlags=10, **kwargs)

Source from the content-addressed store, hash-verified

2023 @_api.make_keyword_only("3.10", "normed")
2024 @_preprocess_data(replace_names=["x", "y"], label_namer="y")
2025 def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
2026 usevlines=True, maxlags=10, **kwargs):
2027 r"""
2028 Plot the cross correlation between *x* and *y*.
2029
2030 The correlation with lag k is defined as
2031 :math:`\sum_n x[n+k] \cdot y^*[n]`, where :math:`y^*` is the complex
2032 conjugate of :math:`y`.
2033
2034 Parameters
2035 ----------
2036 x, y : array-like of length n
2037 Neither *x* nor *y* are run through Matplotlib's unit conversion, so
2038 these should be unit-less arrays.
2039
2040 detrend : callable, default: `.mlab.detrend_none` (no detrending)
2041 A detrending function applied to *x* and *y*. It must have the
2042 signature ::
2043
2044 detrend(x: np.ndarray) -> np.ndarray
2045
2046 normed : bool, default: True
2047 If ``True``, input vectors are normalised to unit length.
2048
2049 usevlines : bool, default: True
2050 Determines the plot style.
2051
2052 If ``True``, vertical lines are plotted from 0 to the xcorr value
2053 using `.Axes.vlines`. Additionally, a horizontal line is plotted
2054 at y=0 using `.Axes.axhline`.
2055
2056 If ``False``, markers are plotted at the xcorr values using
2057 `.Axes.plot`.
2058
2059 maxlags : int, default: 10
2060 Number of lags to show. If None, will return all ``2 * len(x) - 1``
2061 lags.
2062
2063 Returns
2064 -------
2065 lags : array (length ``2*maxlags+1``)
2066 The lag vector.
2067 c : array (length ``2*maxlags+1``)
2068 The auto correlation vector.
2069 line : `.LineCollection` or `.Line2D`
2070 `.Artist` added to the Axes of the correlation:
2071
2072 - `.LineCollection` if *usevlines* is True.
2073 - `.Line2D` if *usevlines* is False.
2074 b : `~matplotlib.lines.Line2D` or None
2075 Horizontal line at 0 if *usevlines* is True
2076 None *usevlines* is False.
2077
2078 Other Parameters
2079 ----------------
2080 linestyle : `~matplotlib.lines.Line2D` property, optional
2081 The linestyle for plotting the data points.
2082 Only used if *usevlines* is ``False``.

Callers 3

acorrMethod · 0.95
xcorrFunction · 0.80

Calls 7

vlinesMethod · 0.95
axhlineMethod · 0.95
plotMethod · 0.95
detrendFunction · 0.85
sqrtMethod · 0.80
dotMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected