@@ -257,28 +257,32 @@ def changed(self):
257
257
def _make_image (self , A , in_bbox , out_bbox , clip_bbox , magnification = 1.0 ,
258
258
unsampled = False , round_to_pixel_border = True ):
259
259
"""
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.
264
264
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.
268
268
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
270
270
appropriate affine transformation will be returned instead.
271
271
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.
282
286
"""
283
287
if A is None :
284
288
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,
534
538
return output , clipped_bbox .x0 , clipped_bbox .y0 , t
535
539
536
540
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' )
538
559
539
560
def _draw_unsampled_image (self , renderer , gc ):
540
561
"""
@@ -679,7 +700,6 @@ def set_array(self, A):
679
700
"""
680
701
# This also needs to be here to override the inherited
681
702
# cm.ScalarMappable.set_array method so it is not invoked by mistake.
682
-
683
703
self .set_data (A )
684
704
685
705
def get_interpolation (self ):
@@ -831,12 +851,12 @@ def get_window_extent(self, renderer=None):
831
851
return bbox .transformed (self .axes .transData )
832
852
833
853
def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
854
+ # docstring inherited
834
855
trans = self .get_transform ()
835
856
# image is created in the canvas coordinate.
836
857
x1 , x2 , y1 , y2 = self .get_extent ()
837
858
bbox = Bbox (np .array ([[x1 , y1 ], [x2 , y2 ]]))
838
859
transformed_bbox = TransformedBbox (bbox , trans )
839
-
840
860
return self ._make_image (
841
861
self ._A , bbox , transformed_bbox , self .axes .bbox , magnification ,
842
862
unsampled = unsampled )
@@ -934,12 +954,11 @@ def _check_unsampled_image(self, renderer):
934
954
return False
935
955
936
956
def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
957
+ # docstring inherited
937
958
if self ._A is None :
938
959
raise RuntimeError ('You must first set the image array' )
939
-
940
960
if unsampled :
941
961
raise ValueError ('unsampled not supported on NonUniformImage' )
942
-
943
962
A = self ._A
944
963
if A .ndim == 2 :
945
964
if A .dtype != np .uint8 :
@@ -958,7 +977,6 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
958
977
B [:, :, 3 ] = 255
959
978
A = B
960
979
self .is_grayscale = False
961
-
962
980
x0 , y0 , v_width , v_height = self .axes .viewLim .bounds
963
981
l , b , r , t = self .axes .bbox .extents
964
982
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):
969
987
int (height ), int (width ),
970
988
(x0 , x0 + v_width , y0 , y0 + v_height ),
971
989
_interpd_ [self ._interpolation ])
972
-
973
990
return im , l , b , IdentityTransform ()
974
991
975
992
def set_data (self , x , y , A ):
@@ -1068,6 +1085,7 @@ def __init__(self, ax,
1068
1085
self .set_data (x , y , A )
1069
1086
1070
1087
def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
1088
+ # docstring inherited
1071
1089
if self ._A is None :
1072
1090
raise RuntimeError ('You must first set the image array' )
1073
1091
if unsampled :
@@ -1209,6 +1227,7 @@ def get_extent(self):
1209
1227
- 0.5 + self .oy , numrows - 0.5 + self .oy )
1210
1228
1211
1229
def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
1230
+ # docstring inherited
1212
1231
fac = renderer .dpi / self .figure .dpi
1213
1232
# fac here is to account for pdf, eps, svg backends where
1214
1233
# 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):
1220
1239
width *= renderer .dpi
1221
1240
height *= renderer .dpi
1222
1241
clip = Bbox ([[0 , 0 ], [width , height ]])
1223
-
1224
1242
return self ._make_image (
1225
1243
self ._A , bbox , bbox , clip , magnification = magnification / fac ,
1226
1244
unsampled = unsampled , round_to_pixel_border = False )
@@ -1304,14 +1322,13 @@ def contains(self, mouseevent):
1304
1322
return inside , {}
1305
1323
1306
1324
def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
1325
+ # docstring inherited
1307
1326
width , height = renderer .get_canvas_width_height ()
1308
-
1309
1327
bbox_in = self .get_window_extent (renderer ).frozen ()
1310
1328
bbox_in ._points /= [width , height ]
1311
1329
bbox_out = self .get_window_extent (renderer )
1312
1330
clip = Bbox ([[0 , 0 ], [width , height ]])
1313
1331
self ._transform = BboxTransform (Bbox ([[0 , 0 ], [1 , 1 ]]), clip )
1314
-
1315
1332
return self ._make_image (
1316
1333
self ._A ,
1317
1334
bbox_in , bbox_out , clip , magnification , unsampled = unsampled )
0 commit comments