@@ -130,9 +130,8 @@ def _draw_list_compositing_images(
130
130
has_images = any (isinstance (x , _ImageBase ) for x in artists )
131
131
132
132
# override the renderer default if suppressComposite is not None
133
- not_composite = renderer .option_image_nocomposite ()
134
- if suppress_composite is not None :
135
- not_composite = suppress_composite
133
+ not_composite = (suppress_composite if suppress_composite is not None
134
+ else renderer .option_image_nocomposite ())
136
135
137
136
if not_composite or not has_images :
138
137
for a in artists :
@@ -146,8 +145,7 @@ def flush_images():
146
145
if len (image_group ) == 1 :
147
146
image_group [0 ].draw (renderer )
148
147
elif len (image_group ) > 1 :
149
- data , l , b = composite_images (
150
- image_group , renderer , mag )
148
+ data , l , b = composite_images (image_group , renderer , mag )
151
149
if data .size != 0 :
152
150
gc = renderer .new_gc ()
153
151
gc .set_clip_rectangle (parent .bbox )
@@ -182,13 +180,17 @@ def _rgb_to_rgba(A):
182
180
class _ImageBase (martist .Artist , cm .ScalarMappable ):
183
181
zorder = 0
184
182
185
- # the 3 following keys seem to be unused now, keep it for
186
- # backward compatibility just in case.
187
- _interpd = _interpd_
188
- # reverse interp dict
189
- _interpdr = {v : k for k , v in six .iteritems (_interpd_ )}
190
- iterpnames = interpolations_names
191
- # <end unused keys>
183
+ @cbook .deprecated ("2.1" )
184
+ def _interpd (self ):
185
+ return _interpd_
186
+
187
+ @cbook .deprecated ("2.1" )
188
+ def _interpdr (self ):
189
+ return {v : k for k , v in six .iteritems (_interpd_ )}
190
+
191
+ @cbook .deprecated ("2.1" )
192
+ def iterpnames (self ):
193
+ return interpolations_names
192
194
193
195
def set_cmap (self , cmap ):
194
196
super (_ImageBase , self ).set_cmap (cmap )
@@ -349,8 +351,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
349
351
out_height = int (ceil (out_height_base ))
350
352
extra_width = (out_width - out_width_base ) / out_width_base
351
353
extra_height = (out_height - out_height_base ) / out_height_base
352
- t += Affine2D ().scale (
353
- 1.0 + extra_width , 1.0 + extra_height )
354
+ t += Affine2D ().scale (1.0 + extra_width , 1.0 + extra_height )
354
355
else :
355
356
out_width = int (out_width_base )
356
357
out_height = int (out_height_base )
@@ -659,7 +660,7 @@ def can_composite(self):
659
660
660
661
def set_resample (self , v ):
661
662
"""
662
- Set whether or not image resampling is used
663
+ Set whether or not image resampling is used.
663
664
664
665
ACCEPTS: True|False
665
666
"""
@@ -669,7 +670,7 @@ def set_resample(self, v):
669
670
self .stale = True
670
671
671
672
def get_resample (self ):
672
- """Return the image resample boolean"""
673
+ """Return the image resample boolean. """
673
674
return self ._resample
674
675
675
676
def set_filternorm (self , filternorm ):
@@ -687,7 +688,7 @@ def set_filternorm(self, filternorm):
687
688
self .stale = True
688
689
689
690
def get_filternorm (self ):
690
- """Return the filternorm setting"""
691
+ """Return the filternorm setting. """
691
692
return self ._filternorm
692
693
693
694
def set_filterrad (self , filterrad ):
@@ -704,7 +705,7 @@ def set_filterrad(self, filterrad):
704
705
self .stale = True
705
706
706
707
def get_filterrad (self ):
707
- """return the filterrad setting"""
708
+ """Return the filterrad setting. """
708
709
return self ._filterrad
709
710
710
711
@@ -770,13 +771,10 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
770
771
771
772
def _check_unsampled_image (self , renderer ):
772
773
"""
773
- return True if the image is better to be drawn unsampled.
774
+ Return whether the image would be better drawn unsampled.
774
775
"""
775
- if (self .get_interpolation () == "none" and
776
- renderer .option_scale_image ()):
777
- return True
778
-
779
- return False
776
+ return (self .get_interpolation () == "none"
777
+ and renderer .option_scale_image ())
780
778
781
779
def set_extent (self , extent ):
782
780
"""
@@ -786,11 +784,8 @@ def set_extent(self, extent):
786
784
to tightly fit the image, regardless of dataLim. Autoscaling
787
785
state is not changed, so following this with ax.autoscale_view
788
786
will redo the autoscaling in accord with dataLim.
789
-
790
787
"""
791
- self ._extent = extent
792
-
793
- xmin , xmax , ymin , ymax = extent
788
+ self ._extent = xmin , xmax , ymin , ymax = extent
794
789
corners = (xmin , ymin ), (xmax , ymax )
795
790
self .axes .update_datalim (corners )
796
791
self .sticky_edges .x [:] = [xmin , xmax ]
@@ -821,8 +816,7 @@ def get_cursor_data(self, event):
821
816
arr = self .get_array ()
822
817
data_extent = Bbox ([[ymin , xmin ], [ymax , xmax ]])
823
818
array_extent = Bbox ([[0 , 0 ], arr .shape [:2 ]])
824
- trans = BboxTransform (boxin = data_extent ,
825
- boxout = array_extent )
819
+ trans = BboxTransform (boxin = data_extent , boxout = array_extent )
826
820
y , x = event .ydata , event .xdata
827
821
i , j = trans .transform_point ([y , x ]).astype (int )
828
822
# Clip the coordinates at array bounds
@@ -971,7 +965,6 @@ def __init__(self, ax,
971
965
norm is a colors.Normalize instance to map luminance to 0-1
972
966
973
967
Additional kwargs are matplotlib.artist properties
974
-
975
968
"""
976
969
super (PcolorImage , self ).__init__ (ax , norm = norm , cmap = cmap )
977
970
self .update (kwargs )
@@ -1095,7 +1088,6 @@ def __init__(self, fig,
1095
1088
origin = None ,
1096
1089
** kwargs
1097
1090
):
1098
-
1099
1091
"""
1100
1092
cmap is a colors.Colormap instance
1101
1093
norm is a colors.Normalize instance to map luminance to 0-1
@@ -1148,7 +1140,6 @@ def __init__(self, bbox,
1148
1140
interp_at_native = True ,
1149
1141
** kwargs
1150
1142
):
1151
-
1152
1143
"""
1153
1144
cmap is a colors.Colormap instance
1154
1145
norm is a colors.Normalize instance to map luminance to 0-1
@@ -1305,30 +1296,30 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
1305
1296
1306
1297
The output formats available depend on the backend being used.
1307
1298
1308
- Arguments:
1309
- *fname*:
1310
- A string containing a path to a filename, or a Python file-like object.
1299
+ Parameters
1300
+ ----------
1301
+ fname : str or file-like
1302
+ Path string to a filename, or a Python file-like object.
1311
1303
If *format* is *None* and *fname* is a string, the output
1312
1304
format is deduced from the extension of the filename.
1313
- * arr*:
1305
+ arr : array-like
1314
1306
An MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA) array.
1315
- Keyword arguments:
1316
- *vmin*/*vmax*: [ None | scalar ]
1307
+ vmin, vmax: [ None | scalar ]
1317
1308
*vmin* and *vmax* set the color scaling for the image by fixing the
1318
1309
values that map to the colormap color limits. If either *vmin*
1319
1310
or *vmax* is None, that limit is determined from the *arr*
1320
1311
min/max value.
1321
- * cmap*:
1322
- cmap is a colors.Colormap instance, e.g., cm.jet.
1323
- If None, default to the rc image.cmap value .
1324
- * format*:
1325
- One of the file extensions supported by the active
1326
- backend. Most backends support png, pdf, ps, eps and svg.
1327
- *origin*
1328
- [ 'upper' | 'lower' ] Indicates where the [0,0] index of
1329
- the array is in the upper left or lower left corner of
1330
- the axes. Defaults to the rc image.origin value .
1331
- *dpi*
1312
+ cmap : matplotlib.colors.Colormap, optional
1313
+ For example, ``cm.viridis``. If ``None``, defaults to the
1314
+ `` image.cmap`` rcParam .
1315
+ format : str
1316
+ One of the file extensions supported by the active backend. Most
1317
+ backends support png, pdf, ps, eps and svg.
1318
+ origin : [ 'upper' | 'lower' ]
1319
+ Indicates whether the ``(0, 0)`` index of the array is in the
1320
+ upper left or lower left corner of the axes. Defaults to the
1321
+ `` image.origin`` rcParam .
1322
+ dpi : int
1332
1323
The DPI to store in the metadata of the file. This does not affect the
1333
1324
resolution of the output image.
1334
1325
"""
@@ -1352,54 +1343,29 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
1352
1343
1353
1344
1354
1345
def pil_to_array (pilImage ):
1346
+ """Load a PIL image and return it as a numpy array.
1347
+
1348
+ Grayscale images are returned as ``(M, N)`` arrays. RGB images are
1349
+ returned as ``(M, N, 3)`` arrays. RGBA images are returned as ``(M, N,
1350
+ 4)`` arrays.
1355
1351
"""
1356
- Load a PIL image and return it as a numpy array. For grayscale
1357
- images, the return array is MxN. For RGB images, the return value
1358
- is MxNx3. For RGBA images the return value is MxNx4
1359
- """
1360
- def toarray (im , dtype = np .uint8 ):
1361
- """Return a 1D array of dtype."""
1362
- # Pillow wants us to use "tobytes"
1363
- if hasattr (im , 'tobytes' ):
1364
- x_str = im .tobytes ('raw' , im .mode )
1365
- else :
1366
- x_str = im .tostring ('raw' , im .mode )
1367
- x = np .fromstring (x_str , dtype )
1368
- return x
1369
-
1370
- if pilImage .mode in ('RGBA' , 'RGBX' ):
1371
- im = pilImage # no need to convert images
1372
- elif pilImage .mode == 'L' :
1373
- im = pilImage # no need to luminance images
1374
- # return MxN luminance array
1375
- x = toarray (im )
1376
- x .shape = im .size [1 ], im .size [0 ]
1377
- return x
1378
- elif pilImage .mode == 'RGB' :
1379
- # return MxNx3 RGB array
1380
- im = pilImage # no need to RGB images
1381
- x = toarray (im )
1382
- x .shape = im .size [1 ], im .size [0 ], 3
1383
- return x
1352
+ if pilImage .mode in ['RGBA' , 'RGBX' , 'RGB' , 'L' ]:
1353
+ # return MxNx4 RGBA, MxNx3 RBA, or MxN luminance array
1354
+ return np .asarray (pilImage )
1384
1355
elif pilImage .mode .startswith ('I;16' ):
1385
1356
# return MxN luminance array of uint16
1386
- im = pilImage
1387
- if im .mode .endswith ('B' ):
1388
- x = toarray ( im , '>u2' )
1357
+ raw = pilImage . tobytes ( 'raw' , pilImage . mode )
1358
+ if pilImage .mode .endswith ('B' ):
1359
+ x = np . fromstring ( raw , '>u2' )
1389
1360
else :
1390
- x = toarray (im , '<u2' )
1391
- x .shape = im .size [1 ], im .size [0 ]
1392
- return x .astype ('=u2' )
1361
+ x = np .fromstring (raw , '<u2' )
1362
+ return x .reshape (pilImage .size [::- 1 ]).astype ('=u2' )
1393
1363
else : # try to convert to an rgba image
1394
1364
try :
1395
- im = pilImage .convert ('RGBA' )
1365
+ pilImage = pilImage .convert ('RGBA' )
1396
1366
except ValueError :
1397
1367
raise RuntimeError ('Unknown image mode' )
1398
-
1399
- # return MxNx4 RGBA array
1400
- x = toarray (im )
1401
- x .shape = im .size [1 ], im .size [0 ], 4
1402
- return x
1368
+ return np .asarray (pilImage ) # return MxNx4 RGBA array
1403
1369
1404
1370
1405
1371
def thumbnail (infile , thumbfile , scale = 0.1 , interpolation = 'bilinear' ,
0 commit comments