Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit baa5f8e

Browse filesBrowse files
authored
Merge pull request #9945 from dstansby/acorr-legend
Only label vertical lines in acorr
2 parents 62c1e34 + cc3a708 commit baa5f8e
Copy full SHA for baa5f8e

File tree

Expand file treeCollapse file tree

3 files changed

+10
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+10
-9
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,6 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
16891689
16901690
Parameters
16911691
----------
1692-
16931692
x : sequence of scalars of length n
16941693
16951694
y : sequence of scalars of length n
@@ -1743,10 +1742,10 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
17431742
x = detrend(np.asarray(x))
17441743
y = detrend(np.asarray(y))
17451744

1746-
c = np.correlate(x, y, mode=2)
1745+
correls = np.correlate(x, y, mode=2)
17471746

17481747
if normed:
1749-
c /= np.sqrt(np.dot(x, x) * np.dot(y, y))
1748+
correls /= np.sqrt(np.dot(x, x) * np.dot(y, y))
17501749

17511750
if maxlags is None:
17521751
maxlags = Nx - 1
@@ -1756,18 +1755,19 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
17561755
'positive < %d' % Nx)
17571756

17581757
lags = np.arange(-maxlags, maxlags + 1)
1759-
c = c[Nx - 1 - maxlags:Nx + maxlags]
1758+
correls = correls[Nx - 1 - maxlags:Nx + maxlags]
17601759

17611760
if usevlines:
1762-
a = self.vlines(lags, [0], c, **kwargs)
1761+
a = self.vlines(lags, [0], correls, **kwargs)
1762+
# Make label empty so only vertical lines get a legend entry
1763+
kwargs.pop('label', '')
17631764
b = self.axhline(**kwargs)
17641765
else:
1765-
17661766
kwargs.setdefault('marker', 'o')
17671767
kwargs.setdefault('linestyle', 'None')
1768-
a, = self.plot(lags, c, **kwargs)
1768+
a, = self.plot(lags, correls, **kwargs)
17691769
b = None
1770-
return lags, c, a, b
1770+
return lags, correls, a, b
17711771

17721772
#### Specialized plotting
17731773

Loading

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def test_acorr():
5151
x = np.random.normal(0, 1, n).cumsum()
5252

5353
fig, ax = plt.subplots()
54-
ax.acorr(x, maxlags=n - 1)
54+
ax.acorr(x, maxlags=n - 1, label='acorr')
55+
ax.legend()
5556

5657

5758
@image_comparison(baseline_images=['spy'], extensions=['png'], style='mpl20')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.