@@ -1021,10 +1021,27 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
10211021 height = (round (t ) + 0.5 ) - (round (b ) - 0.5 )
10221022 width *= magnification
10231023 height *= magnification
1024- im = _image .pcolor (self ._Ax , self ._Ay , A ,
1025- int (height ), int (width ),
1026- (vl .x0 , vl .x1 , vl .y0 , vl .y1 ),
1027- _interpd_ [self ._interpolation ])
1024+ x_pix = np .linspace (vl .x0 , vl .x1 , int (width ))
1025+ y_pix = np .linspace (vl .y0 , vl .y1 , int (height ))
1026+ if self ._interpolation == "nearest" :
1027+ x_mid = (self ._Ax [:- 1 ] + self ._Ax [1 :]) / 2
1028+ y_mid = (self ._Ay [:- 1 ] + self ._Ay [1 :]) / 2
1029+ x_int = x_mid .searchsorted (x_pix )
1030+ y_int = y_mid .searchsorted (y_pix )
1031+ im = A [y_int [:, None ], x_int [None , :]]
1032+ else : # self._interpolation == "bilinear"
1033+ x_int = np .maximum (self ._Ax .searchsorted (x_pix ), 1 ) - 1
1034+ x_frac = (x_pix - self ._Ax [x_int ]) / np .diff (self ._Ax )[x_int ]
1035+ y_int = np .maximum (self ._Ax .searchsorted (y_pix ), 1 ) - 1
1036+ y_frac = (y_pix - self ._Ay [y_int ]) / np .diff (self ._Ay )[y_int ]
1037+ x_int , y_int = np .meshgrid (x_int , y_int , indexing = "xy" )
1038+ x_frac = x_frac [None , :, None ]
1039+ y_frac = y_frac [:, None , None ]
1040+ im = (((1 - y_frac ) * (1 - x_frac ) * A [y_int , x_int ]
1041+ + y_frac * (1 - x_frac ) * A [y_int + 1 , x_int ]
1042+ + (1 - y_frac ) * x_frac * A [y_int , x_int + 1 ]
1043+ + y_frac * x_frac * A [y_int + 1 , x_int + 1 ])
1044+ .astype (np .uint8 ))
10281045 return im , l , b , IdentityTransform ()
10291046
10301047 def set_data (self , x , y , A ):
@@ -1164,11 +1181,15 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
11641181 else :
11651182 A = self ._rgbacache
11661183 vl = self .axes .viewLim
1167- im = _image .pcolor2 (self ._Ax , self ._Ay , A ,
1168- height ,
1169- width ,
1170- (vl .x0 , vl .x1 , vl .y0 , vl .y1 ),
1171- bg )
1184+
1185+ x_pix = np .linspace (vl .x0 , vl .x1 , int (width ))
1186+ y_pix = np .linspace (vl .y0 , vl .y1 , int (height ))
1187+ x_int = np .clip (self ._Ax .searchsorted (x_pix ) - 1 , 0 , len (self ._Ax ) - 2 )
1188+ y_int = np .clip (self ._Ay .searchsorted (y_pix ) - 1 , 0 , len (self ._Ay ) - 2 )
1189+ im = A [y_int [:, None ], x_int [None , :]]
1190+ x_out = (x_pix < self ._Ax [0 ]) | (x_pix > self ._Ax [- 1 ])
1191+ y_out = (y_pix < self ._Ay [0 ]) | (y_pix > self ._Ay [- 1 ])
1192+ im [y_out [:, None ] | x_out [None , :]] = bg
11721193 return im , l , b , IdentityTransform ()
11731194
11741195 def _check_unsampled_image (self ):
0 commit comments