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

Skip to content

Commit 30f99f3

Browse files
authored
Merge pull request #16563 from anntzer/param-aatests
Parametrize imshow antialiased tests.
2 parents 3205ff7 + 1965599 commit 30f99f3

File tree

1 file changed

+17
-75
lines changed

1 file changed

+17
-75
lines changed

lib/matplotlib/tests/test_image.py

Lines changed: 17 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -115,102 +115,44 @@ def test_image_python_io():
115115
plt.imread(buffer)
116116

117117

118+
@pytest.mark.parametrize(
119+
"img_size, fig_size, interpolation",
120+
[(5, 2, "hanning"), # data larger than figure.
121+
(5, 5, "nearest"), # exact resample.
122+
(5, 10, "nearest"), # double sample.
123+
(3, 2.9, "hanning"), # <3 upsample.
124+
(3, 9.1, "nearest"), # >3 upsample.
125+
])
118126
@check_figures_equal(extensions=['png'])
119-
def test_imshow_subsample(fig_test, fig_ref):
120-
# data is bigger than figure, so subsampling with hanning
121-
np.random.seed(19680801)
122-
dpi = 100
123-
A = np.random.rand(int(dpi * 5), int(dpi * 5))
124-
for fig in [fig_test, fig_ref]:
125-
fig.set_size_inches(2, 2)
126-
127-
axs = fig_test.subplots()
128-
axs.set_position([0, 0, 1, 1])
129-
axs.imshow(A, interpolation='antialiased')
130-
axs = fig_ref.subplots()
131-
axs.set_position([0, 0, 1, 1])
132-
axs.imshow(A, interpolation='hanning')
133-
134-
135-
@check_figures_equal(extensions=['png'])
136-
def test_imshow_samesample(fig_test, fig_ref):
137-
# exact resample, so should be same as nearest....
138-
np.random.seed(19680801)
139-
dpi = 100
140-
A = np.random.rand(int(dpi * 5), int(dpi * 5))
141-
for fig in [fig_test, fig_ref]:
142-
fig.set_size_inches(5, 5)
143-
axs = fig_test.subplots()
144-
axs.set_position([0, 0, 1, 1])
145-
axs.imshow(A, interpolation='antialiased')
146-
axs = fig_ref.subplots()
147-
axs.set_position([0, 0, 1, 1])
148-
axs.imshow(A, interpolation='nearest')
149-
150-
151-
@check_figures_equal(extensions=['png'])
152-
def test_imshow_doublesample(fig_test, fig_ref):
153-
# should be exactly a double sample, so should use nearest neighbour
154-
# which is the same as "none"
155-
np.random.seed(19680801)
156-
dpi = 100
157-
A = np.random.rand(int(dpi * 5), int(dpi * 5))
158-
for fig in [fig_test, fig_ref]:
159-
fig.set_size_inches(10, 10)
160-
axs = fig_test.subplots()
161-
axs.set_position([0, 0, 1, 1])
162-
axs.imshow(A, interpolation='antialiased')
163-
axs = fig_ref.subplots()
164-
axs.set_position([0, 0, 1, 1])
165-
axs.imshow(A, interpolation='nearest')
166-
167-
168-
@check_figures_equal(extensions=['png'])
169-
def test_imshow_upsample(fig_test, fig_ref):
170-
# should be less than 3 upsample, so should be nearest...
171-
np.random.seed(19680801)
172-
dpi = 100
173-
A = np.random.rand(int(dpi * 3), int(dpi * 3))
174-
for fig in [fig_test, fig_ref]:
175-
fig.set_size_inches(2.9, 2.9)
176-
axs = fig_test.subplots()
177-
axs.set_position([0, 0, 1, 1])
178-
axs.imshow(A, interpolation='antialiased')
179-
axs = fig_ref.subplots()
180-
axs.set_position([0, 0, 1, 1])
181-
axs.imshow(A, interpolation='hanning')
182-
183-
184-
@check_figures_equal(extensions=['png'])
185-
def test_imshow_upsample3(fig_test, fig_ref):
186-
# should be greater than 3 upsample, so should be nearest...
127+
def test_imshow_antialiased(fig_test, fig_ref,
128+
img_size, fig_size, interpolation):
187129
np.random.seed(19680801)
188-
dpi = 100
189-
A = np.random.rand(int(dpi * 3), int(dpi * 3))
130+
dpi = plt.rcParams["savefig.dpi"]
131+
A = np.random.rand(int(dpi * img_size), int(dpi * img_size))
190132
for fig in [fig_test, fig_ref]:
191-
fig.set_size_inches(9.1, 9.1)
133+
fig.set_size_inches(fig_size, fig_size)
192134
axs = fig_test.subplots()
193135
axs.set_position([0, 0, 1, 1])
194136
axs.imshow(A, interpolation='antialiased')
195137
axs = fig_ref.subplots()
196138
axs.set_position([0, 0, 1, 1])
197-
axs.imshow(A, interpolation='nearest')
139+
axs.imshow(A, interpolation=interpolation)
198140

199141

200142
@check_figures_equal(extensions=['png'])
201143
def test_imshow_zoom(fig_test, fig_ref):
202144
# should be less than 3 upsample, so should be nearest...
203145
np.random.seed(19680801)
204-
dpi = 100
146+
dpi = plt.rcParams["savefig.dpi"]
205147
A = np.random.rand(int(dpi * 3), int(dpi * 3))
206148
for fig in [fig_test, fig_ref]:
207149
fig.set_size_inches(2.9, 2.9)
208150
axs = fig_test.subplots()
209-
axs.imshow(A, interpolation='nearest')
151+
axs.imshow(A, interpolation='antialiased')
210152
axs.set_xlim([10, 20])
211153
axs.set_ylim([10, 20])
212154
axs = fig_ref.subplots()
213-
axs.imshow(A, interpolation='antialiased')
155+
axs.imshow(A, interpolation='nearest')
214156
axs.set_xlim([10, 20])
215157
axs.set_ylim([10, 20])
216158

0 commit comments

Comments
 (0)