Skip to content

Commit abf8001

Browse files
authored
Merge pull request matplotlib#14209 from meeseeksmachine/auto-backport-of-pr-14197-on-v3.1.x
Backport PR matplotlib#14197 on branch v3.1.x (Minor cleanup of acorr/xcoor docs)
2 parents 08b7f88 + 6e53c27 commit abf8001

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
@@ -147,6 +147,7 @@ per-file-ignores =
147147
examples/lines_bars_and_markers/stem_plot.py: E402
148148
examples/lines_bars_and_markers/step_demo.py: E402
149149
examples/lines_bars_and_markers/timeline.py: E402
150+
examples/lines_bars_and_markers/xcorr_acorr_demo.py: E402
150151
examples/misc/agg_buffer.py: E402
151152
examples/misc/anchored_artists.py: E501
152153
examples/misc/contour_manual.py: E501

examples/lines_bars_and_markers/xcorr_acorr_demo.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
@@ -1906,19 +1906,25 @@ def acorr(self, x, **kwargs):
19061906
19071907
Parameters
19081908
----------
1909-
1910-
x : sequence of scalar
1909+
x : array-like
19111910
19121911
detrend : callable, optional, default: `mlab.detrend_none`
1913-
*x* is detrended by the *detrend* callable. Default is no
1914-
normalization.
1912+
*x* is detrended by the *detrend* callable. This must be a
1913+
function ``x = detrend(x)`` accepting and returning an
1914+
`numpy.array`. Default is no normalization.
19151915
19161916
normed : bool, optional, default: True
19171917
If ``True``, input vectors are normalised to unit length.
19181918
19191919
usevlines : bool, optional, default: True
1920-
If ``True``, `Axes.vlines` is used to plot the vertical lines from
1921-
the origin to the acorr. Otherwise, `Axes.plot` is used.
1920+
Determines the plot style.
1921+
1922+
If ``True``, vertical lines are plotted from 0 to the acorr value
1923+
using `Axes.vlines`. Additionally, a horizontal line is plotted
1924+
at y=0 using `Axes.axhline`.
1925+
1926+
If ``False``, markers are plotted at the acorr values using
1927+
`Axes.plot`.
19221928
19231929
maxlags : int, optional, default: 10
19241930
Number of lags to show. If ``None``, will return all
@@ -1927,24 +1933,27 @@ def acorr(self, x, **kwargs):
19271933
Returns
19281934
-------
19291935
lags : array (length ``2*maxlags+1``)
1930-
lag vector.
1936+
The lag vector.
19311937
c : array (length ``2*maxlags+1``)
1932-
auto correlation vector.
1938+
The auto correlation vector.
19331939
line : `.LineCollection` or `.Line2D`
1934-
`.Artist` added to the axes of the correlation.
1940+
`.Artist` added to the axes of the correlation:
19351941
1936-
`.LineCollection` if *usevlines* is True
1937-
`.Line2D` if *usevlines* is False
1942+
- `.LineCollection` if *usevlines* is True.
1943+
- `.Line2D` if *usevlines* is False.
19381944
b : `.Line2D` or None
19391945
Horizontal line at 0 if *usevlines* is True
1940-
None *usevlines* is False
1946+
None *usevlines* is False.
19411947
19421948
Other Parameters
19431949
----------------
1944-
linestyle : `.Line2D` property, optional, default: None
1945-
Only used if usevlines is ``False``.
1950+
linestyle : `.Line2D` property, optional
1951+
The linestyle for plotting the data points.
1952+
Only used if *usevlines* is ``False``.
19461953
19471954
marker : str, optional, default: 'o'
1955+
The marker for plotting the data points.
1956+
Only used if *usevlines* is ``False``.
19481957
19491958
Notes
19501959
-----
@@ -1965,47 +1974,56 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
19651974
19661975
Parameters
19671976
----------
1968-
x : sequence of scalars of length n
1977+
x : array-like of length n
19691978
1970-
y : sequence of scalars of length n
1979+
y : array-like of length n
19711980
19721981
detrend : callable, optional, default: `mlab.detrend_none`
1973-
*x* is detrended by the *detrend* callable. Default is no
1974-
normalization.
1982+
*x* and *y* are detrended by the *detrend* callable. This must be a
1983+
function ``x = detrend(x)`` accepting and returning an
1984+
`numpy.array`. Default is no normalization.
19751985
19761986
normed : bool, optional, default: True
19771987
If ``True``, input vectors are normalised to unit length.
19781988
19791989
usevlines : bool, optional, default: True
1980-
If ``True``, `Axes.vlines` is used to plot the vertical lines from
1981-
the origin to the acorr. Otherwise, `Axes.plot` is used.
1990+
Determines the plot style.
19821991
1983-
maxlags : int, optional
1992+
If ``True``, vertical lines are plotted from 0 to the xcorr value
1993+
using `Axes.vlines`. Additionally, a horizontal line is plotted
1994+
at y=0 using `Axes.axhline`.
1995+
1996+
If ``False``, markers are plotted at the xcorr values using
1997+
`Axes.plot`.
1998+
1999+
maxlags : int, optional, default: 10
19842000
Number of lags to show. If None, will return all ``2 * len(x) - 1``
1985-
lags. Default is 10.
2001+
lags.
19862002
19872003
Returns
19882004
-------
19892005
lags : array (length ``2*maxlags+1``)
1990-
lag vector.
2006+
The lag vector.
19912007
c : array (length ``2*maxlags+1``)
1992-
auto correlation vector.
2008+
The auto correlation vector.
19932009
line : `.LineCollection` or `.Line2D`
1994-
`.Artist` added to the axes of the correlation
2010+
`.Artist` added to the axes of the correlation:
19952011
1996-
`.LineCollection` if *usevlines* is True
1997-
`.Line2D` if *usevlines* is False
2012+
- `.LineCollection` if *usevlines* is True.
2013+
- `.Line2D` if *usevlines* is False.
19982014
b : `.Line2D` or None
19992015
Horizontal line at 0 if *usevlines* is True
2000-
None *usevlines* is False
2016+
None *usevlines* is False.
20012017
20022018
Other Parameters
20032019
----------------
20042020
linestyle : `.Line2D` property, optional
2005-
Only used if usevlines is ``False``.
2021+
The linestyle for plotting the data points.
2022+
Only used if *usevlines* is ``False``.
20062023
2007-
marker : string, optional
2008-
Default is 'o'.
2024+
marker : str, optional, default: 'o'
2025+
The marker for plotting the data points.
2026+
Only used if *usevlines* is ``False``.
20092027
20102028
Notes
20112029
-----

0 commit comments

Comments
 (0)