10000 Merge pull request #14197 from timhoffm/doc-xcorr · matplotlib/matplotlib@7986245 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7986245

Browse files
authored
Merge pull request #14197 from timhoffm/doc-xcorr
Minor cleanup of acorr/xcoor docs
2 parents b0c808d + 88c9989 commit 7986245

File tree

3 files changed

+68
-35
lines changed

3 files changed

+68
-35
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ per-file-ignores =
151151
examples/lines_bars_and_markers/stem_plot.py: E402
152152
examples/lines_bars_and_markers/step_demo.py: E402
153153
examples/lines_bars_and_markers/timeline.py: E402
154+
examples/lines_bars_and_markers/xcorr_acorr_demo.py: E402
154155
examples/misc/agg_buffer.py: E402
155156
examples/misc/anchored_artists.py: E501
156157
examples/misc/contour_manual.py: E501

examples/lines_bars_and_markers/xcorr_acorr_de 10000 mo.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Cross- and Auto-Correlation Demo
44
================================
55
6-
Example use of cross-correlation (`xcorr`) and auto-correlation (`acorr`)
7-
plots.
6+
Example use of cross-correlation (`~.Axes.xcorr`) and auto-correlation
7+
(`~.Axes.acorr`) plots.
88
"""
99
import matplotlib.pyplot as plt
1010
import numpy as np
@@ -18,10 +18,24 @@
1818
fig, [ax1, ax2] = plt.subplots(2, 1, sharex=True)
1919
ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
2020
ax1.grid(True)
21-
ax1.axhline(0, color='black', lw=2)
2221

2322
ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
2423
ax2.grid(True)
25-
ax2.axhline(0, color='black', lw=2)
2624

2725
plt.show()
26+
27+
#############################################################################
28+
#
29+
# ------------
30+
#
31+
# References
32+
# """"""""""
33+
#
34+
# The use of the following functions, methods, classes and modules is shown
35+
# in this example:
36+
37+
import matplotlib
38+
matplotlib.axes.Axes.acorr
39+
matplotlib.axes.Axes.xcorr
40+
matplotlib.pyplot.acorr
41+
matplotlib.pyplot.xcorr

lib/matplotlib/axes/_axes.py

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,19 +1904,25 @@ def acorr(self, x, **kwargs):
19041904
19051905
Parameters
19061906
----------
1907-
1908-
x : sequence of scalar
1907+
x : array-like
19091908
19101909
detrend : callable, optional, default: `mlab.detrend_none`
1911-
*x* is detrended by the *detrend* callable. Default is no
1912-
normalization.
1910+
*x* is detrended by the *detrend* callable. This must be a
1911+
function ``x = detrend(x)`` accepting and returning an
1912+
`numpy.array`. Default is no normalization.
19131913
19141914
normed : bool, optional, default: True
19151915
If ``True``, input vectors are normalised to unit length.
19161916
19171917
usevlines : bool, optional, default: True
1918-
If ``True``, `Axes.vlines` is used to plot the vertical lines from
1919-
the origin to the acorr. Otherwise, `Axes.plot` is used.
1918+
Determines the plot style.
1919+
1920+
If ``True``, vertical lines are plotted from 0 to the acorr value
1921+
using `Axes.vlines`. Additionally, a horizontal line is plotted
1922+
at y=0 using `Axes.axhline`.
1923+
1924+
If ``False``, markers are plotted at the acorr values using
1925+
`Axes.plot`.
19201926
19211927
maxlags : int, optional, default: 10
19221928
Number of lags to show. If ``None``, will return all
@@ -1925,24 +1931,27 @@ def acorr(self, x, **kwargs):
19251931
Returns
19261932
-------
19271933
lags : array (length ``2*maxlags+1``)
1928-
lag vector.
1934+
The lag vector.
19291935
c : array (length ``2*maxlags+1``)
1930-
auto correlation vector.
1936+
The auto correlation vector.
19311937
line : `.LineCollection` or `.Line2D`
1932-
`.Artist` added to the axes of the correlation.
1938+
`.Artist` added to the axes of the correlation:
19331939
1934-
`.LineCollection` if *usevlines* is True
1935-
`.Line2D` if *usevlines* is False
1940+
- `.LineCollection` if *usevlines* is True.
1941+
- `.Line2D` if *usevlines* is False.
19361942
b : `.Line2D` or None
19371943
Horizontal line at 0 if *usevlines* is True
1938-
None *usevlines* is False
1944+
None *usevlines* is False.
19391945
19401946
Other Parameters
19411947
----------------
1942-
linestyle : `.Line2D` property, optional, default: None
1943-
Only used if usevlines is ``False``.
1948+
linestyle : `.Line2D` property, optional
1949+
The linestyle for plotting the data points.
1950+
Only used if *usevlines* is ``False``.
19441951
19451952
marker : str, optional, default: 'o'
1953+
The marker for plotting the data points.
1954+
Only used if *usevlines* is ``False``.
19461955
19471956
Notes
19481957
-----
@@ -1963,47 +1972,56 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
19631972
19641973
Parameters
19651974
----------
1966-
x : sequence of scalars of length n
1975+
x : array-like of length n
19671976
1968-
y : sequence of scalars of length n
1977+
y : array-like of length n
19691978
19701979
detrend : callable, optional, default: `mlab.detrend_none`
1971-
*x* is detrended by the *detrend* callable. Default is no
1972-
normalization.
1980+
*x* and *y* are detrended by the *detrend* callable. This must be a
1981+
function ``x = detrend(x)`` accepting and returning an
1982+
`numpy.array`. Default is no normalization.
19731983
19741984
normed : bool, optional, default: True
19751985
If ``True``, input vectors are normalised to unit length.
19761986
19771987
usevlines : bool, optional, default: True
1978-
If ``True``, `Axes.vlines` is used to plot the vertical lines from
1979-
the origin to the acorr. Otherwise, `Axes.plot` is used.
1988+
Determines the plot style.
19801989
1981-
maxlags : int, optional
1990+
If ``True``, vertical lines are plotted from 0 to the xcorr value
1991+
using `Axes.vlines`. Additionally, a horizontal line is plotted
1992+
at y=0 using `Axes.axhline`.
1993+
1994+
If ``False``, markers are plotted at the xcorr values using
1995+
`Axes.plot`.
1996+
1997+
maxlags : int, optional, default: 10
19821998
Number of lags to show. If None, will return all ``2 * len(x) - 1``
1983-
lags. Default is 10.
1999+
lags.
19842000
19852001
Returns
19862002
-------
19872003
lags : array (length ``2*maxlags+1``)
1988-
lag vector.
2004+
The lag vector.
19892005
c : array (length ``2*maxlags+1``)
1990-
auto correlation vector.
2006+
The auto correlation vector.
19912007
line : `.LineCollection` or `.Line2D`
1992-
`.Artist` added to the axes of the correlation
2008+
`.Artist` added to the axes of the correlation:
19932009
1994-
`.LineCollection` if *usevlines* is True
1995-
`.Line2D` if *usevlines* is False
2010+
- `.LineCollection` if *usevlines* is True.
2011+
- `.Line2D` if *usevlines* is False.
19962012
b : `.Line2D` or None
19972013
Horizontal line at 0 if *usevlines* is True
1998-
None *usevlines* is False
2014+
None *usevlines* is False.
19992015
20002016
Other Parameters
20012017
----------------
20022018
linestyle : `.Line2D` property, optional
2003-
Only used if usevlines is ``False``.
2019+
The linestyle for plotting the data points.
2020+
Only used if *usevlines* is ``False``.
20042021
2005-
marker : string, optional
2006-
Default is 'o'.
2022+
marker : str, optional, default: 'o'
2023+
The marker for plotting the data points.
2024+
Only used if *usevlines* is ``False``.
20072025
20082026
Notes
20092027
-----

0 commit comments

Comments
 (0)
0