Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ def _resample(
if interpolation == 'antialiased':
# don't antialias if upsampling by an integer number or
# if zooming in more than a factor of 3
shape = list(data.shape)
if image_obj.origin == 'upper':
shape[0] = 0
dispx, dispy = transform.transform([shape[1], shape[0]])

pos = np.array([[0, 0], [data.shape[1], data.shape[0]]])
disp = transform.transform(pos)
dispx = np.abs(np.diff(disp[:, 0]))
dispy = np.abs(np.diff(disp[:, 1]))
if ((dispx > 3 * data.shape[1] or
dispx == data.shape[1] or
dispx == 2 * data.shape[1]) and
Expand All @@ -190,7 +189,6 @@ def _resample(
interpolation = 'nearest'
else:
interpolation = 'hanning'

out = np.zeros(out_shape + data.shape[2:], data.dtype) # 2D->2D, 3D->3D.
if resample is None:
resample = image_obj.get_resample()
Expand Down
18 changes: 18 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ def test_imshow_upsample3(fig_test, fig_ref):
axs.imshow(A, interpolation='nearest')


@check_figures_equal(extensions=['png'])
def test_imshow_zoom(fig_test, fig_ref):
# should be less than 3 upsample, so should be nearest...
np.random.seed(19680801)
dpi = 100
A = np.random.rand(int(dpi * 3), int(dpi * 3))
for fig in [fig_test, fig_ref]:
fig.set_size_inches(2.9, 2.9)
axs = fig_test.subplots()
axs.imshow(A, interpolation='nearest')
axs.set_xlim([10, 20])
axs.set_ylim([10, 20])
axs = fig_ref.subplots()
axs.imshow(A, interpolation='antialiased')
axs.set_xlim([10, 20])
axs.set_ylim([10, 20])


@check_figures_equal()
def test_imshow_pil(fig_test, fig_ref):
style.use("default")
Expand Down