@@ -1295,7 +1295,7 @@ def __init__(self, name, colormaps, combination_mode):
1295
1295
self .n_variates = len (colormaps )
1296
1296
self ._rgba_bad = (0.0 , 0.0 , 0.0 , 0.0 ) # If bad, don't paint anything.
1297
1297
1298
- def __call__ (self , X , alpha = None , bytes = False ):
1298
+ def __call__ (self , X , alpha = None , bytes = False , clip = True ):
1299
1299
r"""
1300
1300
Parameters
1301
1301
----------
@@ -1315,6 +1315,8 @@ def __call__(self, X, alpha=None, bytes=False):
1315
1315
If False (default), the returned RGBA values will be floats in the
1316
1316
interval ``[0, 1]`` otherwise they will be `numpy.uint8`\s in the
1317
1317
interval ``[0, 255]``.
1318
+ clip : bool
1319
+ If True, clip output to 0 to 1
1318
1320
1319
1321
Returns
1320
1322
-------
@@ -1340,17 +1342,24 @@ def __call__(self, X, alpha=None, bytes=False):
1340
1342
1341
1343
rgba [mask_bad ] = self .get_bad ()
1342
1344
1343
- rgba = np .clip (rgba , 0 , 1 )
1345
+ if clip :
1346
+ rgba = np .clip (rgba , 0 , 1 )
1344
1347
1345
1348
if alpha is not None :
1346
- alpha = np .clip (alpha , 0 , 1 )
1349
+ if clip :
1350
+ alpha = np .clip (alpha , 0 , 1 )
1347
1351
if alpha .shape not in [(), np .array (X [0 ]).shape ]:
1348
1352
raise ValueError (
1349
1353
f"alpha is array-like but its shape { alpha .shape } does "
1350
1354
f"not match that of X[0] { np .array (X [0 ]).shape } " )
1351
1355
rgba [..., - 1 ] *= alpha
1352
1356
1353
1357
if bytes :
1358
+ if not clip :
1359
+ raise ValueError (
1360
+ "clip cannot be false while bytes is true"
1361
+ " as uint8 does not support values below 0"
1362
+ " or above 255." )
1354
1363
rgba = (rgba * 255 ).astype ('uint8' )
1355
1364
1356
1365
if not np .iterable (X [0 ]):
@@ -1736,24 +1745,20 @@ def __getitem__(self, item):
1736
1745
if not self ._isinit :
1737
1746
self ._init ()
1738
1747
if item == 0 :
1739
- cmap = Colormap (self .name + '0' , self .N )
1740
1748
one_d_lut = self ._lut [:, self ._origin [1 ]]
1749
+ new_cmap = ListedColormap (one_d_lut , name = self .name + '_0' , N = self .N )
1750
+
1741
1751
elif item == 1 :
1742
- cmap = Colormap (self .name + '1' , self .M )
1743
1752
one_d_lut = self ._lut [self ._origin [0 ], :]
1753
+ new_cmap = ListedColormap (one_d_lut , name = self .name + '_1' , N = self .M )
1744
1754
else :
1745
1755
raise KeyError (f"only 0 or 1 are"
1746
1756
f" valid keys for BivarColormap, not { item !r} " )
1747
- cmap ._lut = np .zeros ((self .N + 3 , 4 ), float )
1748
- cmap ._lut [:- 3 ] = one_d_lut
1749
- cmap .set_bad (self ._rgba_bad )
1750
- self ._rgba_outside
1757
+ new_cmap ._rgba_bad = self ._rgba_bad
1751
1758
if self .shape in ['ignore' , 'circleignore' ]:
1752
- cmap .set_under (self ._rgba_outside )
1753
- cmap .set_over (self ._rgba_outside )
1754
- cmap ._set_extremes ()
1755
- cmap ._isinit = True
1756
- return cmap
1759
+ new_cmap .set_over (self ._rgba_outside )
1760
+ new_cmap .set_under (self ._rgba_outside )
1761
+ return new_cmap
1757
1762
1758
1763
def _repr_png_ (self ):
1759
1764
"""Generate a PNG representation of the BivarColormap."""
0 commit comments