Skip to content

Only label vertical lines in acorr #9945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/acorr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down