@@ -115,102 +115,44 @@ def test_image_python_io():
115
115
plt .imread (buffer )
116
116
117
117
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
+ ])
118
126
@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 ):
187
129
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 ))
190
132
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 )
192
134
axs = fig_test .subplots ()
193
135
axs .set_position ([0 , 0 , 1 , 1 ])
194
136
axs .imshow (A , interpolation = 'antialiased' )
195
137
axs = fig_ref .subplots ()
196
138
axs .set_position ([0 , 0 , 1 , 1 ])
197
- axs .imshow (A , interpolation = 'nearest' )
139
+ axs .imshow (A , interpolation = interpolation )
198
140
199
141
200
142
@check_figures_equal (extensions = ['png' ])
201
143
def test_imshow_zoom (fig_test , fig_ref ):
202
144
# should be less than 3 upsample, so should be nearest...
203
145
np .random .seed (19680801 )
204
- dpi = 100
146
+ dpi = plt . rcParams [ "savefig.dpi" ]
205
147
A = np .random .rand (int (dpi * 3 ), int (dpi * 3 ))
206
148
for fig in [fig_test , fig_ref ]:
207
149
fig .set_size_inches (2.9 , 2.9 )
208
150
axs = fig_test .subplots ()
209
- axs .imshow (A , interpolation = 'nearest ' )
151
+ axs .imshow (A , interpolation = 'antialiased ' )
210
152
axs .set_xlim ([10 , 20 ])
211
153
axs .set_ylim ([10 , 20 ])
212
154
axs = fig_ref .subplots ()
213
- axs .imshow (A , interpolation = 'antialiased ' )
155
+ axs .imshow (A , interpolation = 'nearest ' )
214
156
axs .set_xlim ([10 , 20 ])
215
157
axs .set_ylim ([10 , 20 ])
216
158
0 commit comments