File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -176,11 +176,10 @@ def _resample(
176176 if interpolation == 'antialiased' :
177177 # don't antialias if upsampling by an integer number or
178178 # if zooming in more than a factor of 3
179- shape = list (data .shape )
180- if image_obj .origin == 'upper' :
181- shape [0 ] = 0
182- dispx , dispy = transform .transform ([shape [1 ], shape [0 ]])
183-
179+ pos = np .array ([[0 , 0 ], [data .shape [1 ], data .shape [0 ]]])
180+ disp = transform .transform (pos )
181+ dispx = np .abs (np .diff (disp [:, 0 ]))
182+ dispy = np .abs (np .diff (disp [:, 1 ]))
184183 if ((dispx > 3 * data .shape [1 ] or
185184 dispx == data .shape [1 ] or
186185 dispx == 2 * data .shape [1 ]) and
@@ -190,7 +189,6 @@ def _resample(
190189 interpolation = 'nearest'
191190 else :
192191 interpolation = 'hanning'
193-
194192 out = np .zeros (out_shape + data .shape [2 :], data .dtype ) # 2D->2D, 3D->3D.
195193 if resample is None :
196194 resample = image_obj .get_resample ()
Original file line number Diff line number Diff line change @@ -198,6 +198,24 @@ def test_imshow_upsample3(fig_test, fig_ref):
198198 axs .imshow (A , interpolation = 'nearest' )
199199
200200
201+ @check_figures_equal (extensions = ['png' ])
202+ def test_imshow_zoom (fig_test , fig_ref ):
203+ # should be less than 3 upsample, so should be nearest...
204+ np .random .seed (19680801 )
205+ dpi = 100
206+ A = np .random .rand (int (dpi * 3 ), int (dpi * 3 ))
207+ for fig in [fig_test , fig_ref ]:
208+ fig .set_size_inches (2.9 , 2.9 )
209+ axs = fig_test .subplots ()
210+ axs .imshow (A , interpolation = 'nearest' )
211+ axs .set_xlim ([10 , 20 ])
212+ axs .set_ylim ([10 , 20 ])
213+ axs = fig_ref .subplots ()
214+ axs .imshow (A , interpolation = 'antialiased' )
215+ axs .set_xlim ([10 , 20 ])
216+ axs .set_ylim ([10 , 20 ])
217+
218+
201219@check_figures_equal ()
202220def test_imshow_pil (fig_test , fig_ref ):
203221 style .use ("default" )
You can’t perform that action at this time.
0 commit comments