8000 FIX: fix anti-aliasing zoom bug · matplotlib/matplotlib@436dd6e · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit 436dd6e

Browse files
committed
FIX: fix anti-aliasing zoom bug
1 parent 09c8381 commit 436dd6e

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

lib/matplotlib/image.py

Lines changed: 4 additions & 6 deletions
8000
Original file line numberDiff line numberDiff 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()

lib/matplotlib/tests/test_image.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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()
202220
def test_imshow_pil(fig_test, fig_ref):
203221
style.use("default")

0 commit comments

Comments
 (0)
0