Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53c8d6a

Browse files
authored
Merge pull request #16365 from pharshalp/last_test_improvement
TST: test_acorr (replaced image comparison with figure comparion)
2 parents cb904b1 + 19fc352 commit 53c8d6a

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed
Binary file not shown.

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,23 @@ def test_label_loc_rc(fig_test, fig_ref):
9595
cbar.set_label("Z Label", x=1, ha='right')
9696

9797

98-
@image_comparison(['acorr.png'], style='mpl20')
99-
def test_acorr():
100-
# Remove this line when this test image is regenerated.
101-
plt.rcParams['text.kerning_factor'] = 6
102-
98+
@check_figures_equal(extensions=["png"])
99+
def test_acorr(fig_test, fig_ref):
103100
np.random.seed(19680801)
104-
n = 512
105-
x = np.random.normal(0, 1, n).cumsum()
106-
107-
fig, ax = plt.subplots()
108-
ax.acorr(x, maxlags=n - 1, label='acorr')
109-
ax.legend()
101+
Nx = 512
102+
x = np.random.normal(0, 1, Nx).cumsum()
103+
maxlags = Nx-1
104+
105+
fig_test, ax_test = plt.subplots()
106+
ax_test.acorr(x, maxlags=maxlags)
107+
108+
fig_ref, ax_ref = plt.subplots()
109+
# Normalized autocorrelation
110+
norm_auto_corr = np.correlate(x, x, mode="full")/np.dot(x, x)
111+
lags = np.arange(-maxlags, maxlags+1)
112+
norm_auto_corr = norm_auto_corr[Nx-1-maxlags:Nx+maxlags]
113+
ax_ref.vlines(lags, [0], norm_auto_corr)
114+
ax_ref.axhline(y=0, xmin=0, xmax=1)
110115

111116

112117
@check_figures_equal(extensions=["png"])

0 commit comments

Comments
 (0)