8000 Merge pull request #25832 from abcnishant007/patch-1 · matplotlib/matplotlib@9e1359d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e1359d

Browse files
authored
Merge pull request #25832 from abcnishant007/patch-1
[BUG] Prevent under the hood downcasting of values
2 parents b5f227e + 9b2bdad commit 9e1359d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
21152115
correls = np.correlate(x, y, mode="full")
21162116

21172117
if normed:
2118-
correls /= np.sqrt(np.dot(x, x) * np.dot(y, y))
2118+
correls = correls / np.sqrt(np.dot(x, x) * np.dot(y, y))
21192119

21202120
if maxlags is None:
21212121
maxlags = Nx - 1

lib/matplotlib/tests/test_axes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ def test_acorr(fig_test, fig_ref):
170170
ax_ref.axhline(y=0, xmin=0, xmax=1)
171171

172172

173+
@check_figures_equal(extensions=["png"])
174+
def test_acorr_integers(fig_test, fig_ref):
175+
np.random.seed(19680801)
176+
Nx = 51
177+
x = (np.random.rand(Nx) * 10).cumsum()
178+
x = (np.ceil(x)).astype(np.int64)
179+
maxlags = Nx-1
180+
181+
ax_test = fig_test.subplots()
182+
ax_test.acorr(x, maxlags=maxlags)
183+
184+
ax_ref = fig_ref.subplots()
185+
186+
# Normalized autocorrelation
187+
norm_auto_corr = np.correlate(x, x, mode="full")/np.dot(x, x)
188+
lags = np.arange(-maxlags, maxlags+1)
189+
norm_auto_corr = norm_auto_corr[Nx-1-maxlags:Nx+maxlags]
190+
ax_ref.vlines(lags, [0], norm_auto_corr)
191+
ax_ref.axhline(y=0, xmin=0, xmax=1)
192+
193+
173194
@check_figures_equal(extensions=["png"])
174195
def test_spy(fig_test, fig_ref):
175196
np.random.seed(19680801)

0 commit comments

Comments
 (0)
0