@@ -630,6 +630,7 @@ def __init__(self, fig,
630630 self .ox = offsetx
631631 self .oy = offsety
632632 self .update (kwargs )
633+ self .magnification = 1.0
633634
634635 def contains (self , mouseevent ):
635636 """Test whether the mouse event occured within the image.
@@ -659,22 +660,30 @@ def get_extent(self):
659660 - 0.5 + self .oy , numrows - 0.5 + self .oy )
660661
661662 def make_image (self , magnification = 1.0 ):
662- # had to introduce argument magnification to satisfy the unit test
663- # figimage_demo.py. I have no idea, how magnification should be used
664- # within the function. It should be !=1.0 only for non-default DPI<
665- # settings in the PS backend, as introduced by patch #1562394
666- # Probably Nicholas Young should look over this code and see, how
667- # magnification should be handled correctly.
668663 if self ._A is None :
669664 raise RuntimeError ('You must first set the image array' )
670665
671666 x = self .to_rgba (self ._A , self ._alpha )
672-
673- im = _image .fromarray (x , 1 )
667+ self .magnification = magnification
668+ # if magnification is not one, we need to resize
669+ ismag = magnification != 1
670+ #if ismag: raise RuntimeError
671+ if ismag :
672+ isoutput = 0
673+ else :
674+ isoutput = 1
675+ im = _image .fromarray (x , isoutput )
674676 fc = self .figure .get_facecolor ()
675677 im .set_bg ( * mcolors .colorConverter .to_rgba (fc , 0 ) )
676678 im .is_grayscale = (self .cmap .name == "gray" and
677679 len (self ._A .shape ) == 2 )
680+
681+ if ismag :
682+ numrows , numcols = self .get_size ()
683+ numrows *= magnification
684+ numcols *= magnification
685+ im .set_interpolation (_image .NEAREST )
686+ im .resize (numcols , numrows )
678687 if self .origin == 'upper' :
679688 im .flipud_out ()
680689
@@ -683,9 +692,8 @@ def make_image(self, magnification=1.0):
683692 def draw (self , renderer , * args , ** kwargs ):
684693 if not self .get_visible (): return
685694 # todo: we should be able to do some cacheing here
686- im = self .make_image ()
687-
688- renderer .draw_image (round (self .ox ), round (self .oy ), im , self .figure .bbox ,
695+ im = self .make_image (renderer .get_image_magnification ())
696+ renderer .draw_image (round (self .ox / self .magnification ), round (self .oy / self .magnification ), im , self .figure .bbox ,
689697 * self .get_transformed_clip_path_and_affine ())
690698
691699 def write_png (self , fname ):
@@ -772,7 +780,7 @@ def toarray(im):
772780 x .shape = im .size [1 ], im .size [0 ], 4
773781 return x
774782
775- def thumbnail (infile , thumbfile , scale = 0.1 , interpolation = 'bilinear' ,
783+ def thumbnail (infile , thumbfile , scale = 0.1 , interpolation = 'bilinear' ,
776784 preview = False ):
777785 """
778786 make a thumbnail of image in *infile* with output filename
0 commit comments