@@ -257,28 +257,32 @@ def changed(self):
257257 def _make_image (self , A , in_bbox , out_bbox , clip_bbox , magnification = 1.0 ,
258258 unsampled = False , round_to_pixel_border = True ):
259259 """
260- Normalize, rescale and color the image `A` from the given
261- in_bbox (in data space), to the given out_bbox (in pixel
262- space) clipped to the given clip_bbox (also in pixel space),
263- and magnified by the magnification factor.
260+ Normalize, rescale, and colormap the image *A* from the given *in_bbox*
261+ (in data space), to the given * out_bbox* (in pixel space) clipped to
262+ the given * clip_bbox* (also in pixel space), and magnified by the
263+ * magnification* factor.
264264
265- `A` may be a greyscale image (MxN ) with a dtype of ` float32` ,
266- `float64`, ` float128`, ` uint16` or ` uint8` , or an RGBA image (MxNx4)
267- with a dtype of ` float32`, ` float64`, ` float128` , or ` uint8` .
265+ *A* may be a greyscale image (M, N ) with a dtype of float32, float64 ,
266+ float128, uint16 or uint8, or an (M, N, 4) RGBA image with a dtype of
267+ float32, float64, float128, or uint8.
268268
269- If ` unsampled` is True, the image will not be scaled, but an
269+ If * unsampled* is True, the image will not be scaled, but an
270270 appropriate affine transformation will be returned instead.
271271
272- If `round_to_pixel_border` is True, the output image size will
273- be rounded to the nearest pixel boundary. This makes the
274- images align correctly with the axes. It should not be used
275- in cases where you want exact scaling, however, such as
276- FigureImage.
277-
278- Returns the resulting (image, x, y, trans), where (x, y) is
279- the upper left corner of the result in pixel space, and
280- `trans` is the affine transformation from the image to pixel
281- space.
272+ If *round_to_pixel_border* is True, the output image size will be
273+ rounded to the nearest pixel boundary. This makes the images align
274+ correctly with the axes. It should not be used if exact scaling is
275+ needed, such as for `FigureImage`.
276+
277+ Returns
278+ -------
279+ image : (M, N, 4) uint8 array
280+ The RGBA image, resampled unless *unsampled* is True.
281+ x, y : float
282+ The upper left corner where the image should be drawn, in pixel
283+ space.
284+ trans : Affine2D
285+ The affine transformation from image to pixel space.
282286 """
283287 if A is None :
284288 raise RuntimeError ('You must first set the image '
@@ -534,7 +538,24 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
534538 return output , clipped_bbox .x0 , clipped_bbox .y0 , t
535539
536540 def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
537- raise RuntimeError ('The make_image method must be overridden.' )
541+ """
542+ Normalize, rescale, and colormap this image's data for rendering using
543+ *renderer*, with the given *magnification*.
544+
545+ If *unsampled* is True, the image will not be scaled, but an
546+ appropriate affine transformation will be returned instead.
547+
548+ Returns
549+ -------
550+ image : (M, N, 4) uint8 array
551+ The RGBA image, resampled unless *unsampled* is True.
552+ x, y : float
553+ The upper left corner where the image should be drawn, in pixel
554+ space.
555+ trans : Affine2D
556+ The affine transformation from image to pixel space.
557+ """
558+ raise NotImplementedError ('The make_image method must be overridden' )
538559
539560 def _draw_unsampled_image (self , renderer , gc ):
540561 """
@@ -679,7 +700,6 @@ def set_array(self, A):
679700 """
680701 # This also needs to be here to override the inherited
681702 # cm.ScalarMappable.set_array method so it is not invoked by mistake.
682-
683703 self .set_data (A )
684704
685705 def get_interpolation (self ):
@@ -831,12 +851,12 @@ def get_window_extent(self, renderer=None):
831851 return bbox .transformed (self .axes .transData )
832852
833853 def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
854+ # docstring inherited
834855 trans = self .get_transform ()
835856 # image is created in the canvas coordinate.
836857 x1 , x2 , y1 , y2 = self .get_extent ()
837858 bbox = Bbox (np .array ([[x1 , y1 ], [x2 , y2 ]]))
838859 transformed_bbox = TransformedBbox (bbox , trans )
839-
840860 return self ._make_image (
841861 self ._A , bbox , transformed_bbox , self .axes .bbox , magnification ,
842862 unsampled = unsampled )
@@ -934,12 +954,11 @@ def _check_unsampled_image(self, renderer):
934954 return False
935955
936956 def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
957+ # docstring inherited
937958 if self ._A is None :
938959 raise RuntimeError ('You must first set the image array' )
939-
940960 if unsampled :
941961 raise ValueError ('unsampled not supported on NonUniformImage' )
942-
943962 A = self ._A
944963 if A .ndim == 2 :
945964 if A .dtype != np .uint8 :
@@ -958,7 +977,6 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
958977 B [:, :, 3 ] = 255
959978 A = B
960979 self .is_grayscale = False
961-
962980 x0 , y0 , v_width , v_height = self .axes .viewLim .bounds
963981 l , b , r , t = self .axes .bbox .extents
964982 width = (np .round (r ) + 0.5 ) - (np .round (l ) - 0.5 )
@@ -969,7 +987,6 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
969987 int (height ), int (width ),
970988 (x0 , x0 + v_width , y0 , y0 + v_height ),
971989 _interpd_ [self ._interpolation ])
972-
973990 return im , l , b , IdentityTransform ()
974991
975992 def set_data (self , x , y , A ):
@@ -1068,6 +1085,7 @@ def __init__(self, ax,
10681085 self .set_data (x , y , A )
10691086
10701087 def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
1088+ # docstring inherited
10711089 if self ._A is None :
10721090 raise RuntimeError ('You must first set the image array' )
10731091 if unsampled :
@@ -1209,6 +1227,7 @@ def get_extent(self):
12091227 - 0.5 + self .oy , numrows - 0.5 + self .oy )
12101228
12111229 def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
1230+ # docstring inherited
12121231 fac = renderer .dpi / self .figure .dpi
12131232 # fac here is to account for pdf, eps, svg backends where
12141233 # figure.dpi is set to 72. This means we need to scale the
@@ -1220,7 +1239,6 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
12201239 width *= renderer .dpi
12211240 height *= renderer .dpi
12221241 clip = Bbox ([[0 , 0 ], [width , height ]])
1223-
12241242 return self ._make_image (
12251243 self ._A , bbox , bbox , clip , magnification = magnification / fac ,
12261244 unsampled = unsampled , round_to_pixel_border = False )
@@ -1304,14 +1322,13 @@ def contains(self, mouseevent):
13041322 return inside , {}
13051323
13061324 def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
1325+ # docstring inherited
13071326 width , height = renderer .get_canvas_width_height ()
1308-
13091327 bbox_in = self .get_window_extent (renderer ).frozen ()
13101328 bbox_in ._points /= [width , height ]
13111329 bbox_out = self .get_window_extent (renderer )
13121330 clip = Bbox ([[0 , 0 ], [width , height ]])
13131331 self ._transform = BboxTransform (Bbox ([[0 , 0 ], [1 , 1 ]]), clip )
1314-
13151332 return self ._make_image (
13161333 self ._A ,
13171334 bbox_in , bbox_out , clip , magnification , unsampled = unsampled )
0 commit comments