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

Skip to content

Commit 6ec39d5

Browse files
authored
Merge pull request #17191 from anntzer/unsampled-image
MNT: Inline unsampled-image path; remove renderer kwarg from _check_unsampled_image.
2 parents 1e94c13 + 0635bb7 commit 6ec39d5

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

lib/matplotlib/image.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -572,21 +572,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
572572
"""
573573
raise NotImplementedError('The make_image method must be overridden')
574574

575-
def _draw_unsampled_image(self, renderer, gc):
576-
"""
577-
Draw unsampled image. The renderer should support a draw_image method
578-
with scale parameter.
579-
"""
580-
im, l, b, trans = self.make_image(renderer, unsampled=True)
581-
582-
if im is None:
583-
return
584-
585-
trans = Affine2D().scale(im.shape[1], im.shape[0]) + trans
586-
587-
renderer.draw_image(gc, l, b, im, trans)
588-
589-
def _check_unsampled_image(self, renderer):
575+
def _check_unsampled_image(self):
590576
"""
591577
Return whether the image is better to be drawn unsampled.
592578
@@ -600,22 +586,23 @@ def draw(self, renderer, *args, **kwargs):
600586
if not self.get_visible():
601587
self.stale = False
602588
return
603-
604589
# for empty images, there is nothing to draw!
605590
if self.get_array().size == 0:
606591
self.stale = False
607592
return
608-
609593
# actually render the image.
610594
gc = renderer.new_gc()
611595
self._set_gc_clip(gc)
612596
gc.set_alpha(self._get_scalar_alpha())
613597
gc.set_url(self.get_url())
614598
gc.set_gid(self.get_gid())
615-
616-
if (self._check_unsampled_image(renderer) and
617-
self.get_transform().is_affine):
618-
self._draw_unsampled_image(renderer, gc)
599+
if (renderer.option_scale_image() # Renderer supports transform kwarg.
600+
and self._check_unsampled_image()
601+
and self.get_transform().is_affine):
602+
im, l, b, trans = self.make_image(renderer, unsampled=True)
603+
if im is not None:
604+
trans = Affine2D().scale(im.shape[1], im.shape[0]) + trans
605+
renderer.draw_image(gc, l, b, im, trans)
619606
else:
620607
im, l, b, trans = self.make_image(
621608
renderer, renderer.get_image_magnification())
@@ -905,10 +892,9 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
905892
self.get_clip_box() or self.axes.bbox,
906893
magnification, unsampled=unsampled)
907894

908-
def _check_unsampled_image(self, renderer):
895+
def _check_unsampled_image(self):
909896
"""Return whether the image would be better drawn unsampled."""
910-
return (self.get_interpolation() == "none"
911-
and renderer.option_scale_image())
897+
return self.get_interpolation() == "none"
912898

913899
def set_extent(self, extent):
914900
"""
@@ -1000,7 +986,7 @@ def __init__(self, ax, *, interpolation='nearest', **kwargs):
1000986
super().__init__(ax, **kwargs)
1001987
self.set_interpolation(interpolation)
1002988

1003-
def _check_unsampled_image(self, renderer):
989+
def _check_unsampled_image(self):
1004990
"""Return False. Do not use unsampled image."""
1005991
return False
1006992

@@ -1192,7 +1178,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
11921178
bg)
11931179
return im, l, b, IdentityTransform()
11941180

1195-
def _check_unsampled_image(self, renderer):
1181+
def _check_unsampled_image(self):
11961182
return False
11971183

11981184
def set_data(self, x, y, A):

0 commit comments

Comments
 (0)