diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 5d05169728aa..85dcc041d089 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1689,7 +1689,6 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none, Parameters ---------- - x : sequence of scalars of length n y : sequence of scalars of length n @@ -1743,10 +1742,10 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none, x = detrend(np.asarray(x)) y = detrend(np.asarray(y)) - c = np.correlate(x, y, mode=2) + correls = np.correlate(x, y, mode=2) if normed: - c /= np.sqrt(np.dot(x, x) * np.dot(y, y)) + correls /= np.sqrt(np.dot(x, x) * np.dot(y, y)) if maxlags is None: maxlags = Nx - 1 @@ -1756,18 +1755,19 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none, 'positive < %d' % Nx) lags = np.arange(-maxlags, maxlags + 1) - c = c[Nx - 1 - maxlags:Nx + maxlags] + correls = correls[Nx - 1 - maxlags:Nx + maxlags] if usevlines: - a = self.vlines(lags, [0], c, **kwargs) + a = self.vlines(lags, [0], correls, **kwargs) + # Make label empty so only vertical lines get a legend entry + kwargs.pop('label', '') b = self.axhline(**kwargs) else: - kwargs.setdefault('marker', 'o') kwargs.setdefault('linestyle', 'None') - a, = self.plot(lags, c, **kwargs) + a, = self.plot(lags, correls, **kwargs) b = None - return lags, c, a, b + return lags, correls, a, b #### Specialized plotting diff --git a/lib/matplotlib/tests/baseline_images/test_axes/acorr.png b/lib/matplotlib/tests/baseline_images/test_axes/acorr.png index 970a181d8c03..62ccbab1bc7b 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/acorr.png and b/lib/matplotlib/tests/baseline_images/test_axes/acorr.png differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 21ac6efc3b45..f10bc90ceb9d 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -51,7 +51,8 @@ def test_acorr(): x = np.random.normal(0, 1, n).cumsum() fig, ax = plt.subplots() - ax.acorr(x, maxlags=n - 1) + ax.acorr(x, maxlags=n - 1, label='acorr') + ax.legend() @image_comparison(baseline_images=['spy'], extensions=['png'], style='mpl20')