@@ -728,14 +728,16 @@ def __call__(self, X, alpha=None, bytes=False):
728
728
bytes : bool
729
729
If False (default), the returned RGBA values will be floats in the
730
730
interval ``[0, 1]`` otherwise they will be `numpy.uint8`\s in the
731
- interval ``[0, 255]``
731
+ interval ``[0, 255]``.
732
732
733
733
Returns
734
734
-------
735
735
Tuple of RGBA values if X is scalar, otherwise an array of
736
736
RGBA values with a shape of ``X.shape + (4, )``.
737
737
"""
738
738
rgba , mask = self ._get_rgba_and_mask (X , alpha = alpha , bytes = bytes )
739
+ if not np .iterable (X ):
740
+ rgba = tuple (rgba )
739
741
return rgba
740
742
741
743
def _get_rgba_and_mask (self , X , alpha = None , bytes = False ):
@@ -758,9 +760,9 @@ def _get_rgba_and_mask(self, X, alpha=None, bytes=False):
758
760
759
761
Returns
760
762
-------
761
- ( colors, mask), where color is a tuple of RGBA values if X is scalar,
762
- otherwise an array of RGBA values with a shape of ``X.shape + (4, )``,
763
- and mask is a boolean array .
763
+ colors : array of RGBA values with a shape of ``X.shape + (4, )``.
764
+ mask : boolean array with True where the input is ``np.nan`` or
765
+ masked .
764
766
"""
765
767
if not self ._isinit :
766
768
self ._init ()
@@ -805,8 +807,6 @@ def _get_rgba_and_mask(self, X, alpha=None, bytes=False):
805
807
if (lut [- 1 ] == 0 ).all ():
806
808
rgba [mask_bad ] = (0 , 0 , 0 , 0 )
807
809
808
- if not np .iterable (X ):
809
- rgba = tuple (rgba )
810
810
return rgba , mask_bad
811
811
812
812
def __copy__ (self ):
@@ -1290,9 +1290,7 @@ def __init__(self, colormaps, combination_mode, name='multivariate colormap'):
1290
1290
" Colormap or valid strings." )
1291
1291
1292
1292
self ._colormaps = colormaps
1293
- if combination_mode not in ['sRGB_add' , 'sRGB_sub' ]:
1294
- raise ValueError ("Combination_mode must be 'sRGB_add' or 'sRGB_sub',"
1295
- f" { combination_mode !r} is not allowed." )
1293
+ _api .check_in_list (['sRGB_add' , 'sRGB_sub' ], combination_mode = combination_mode )
1296
1294
self ._combination_mode = combination_mode
1297
1295
self .n_variates = len (colormaps )
1298
1296
self ._rgba_bad = (0.0 , 0.0 , 0.0 , 0.0 ) # If bad, don't paint anything.
@@ -1331,10 +1329,8 @@ def __call__(self, X, alpha=None, bytes=False, clip=True):
1331
1329
f'For the selected colormap the data must have a first dimension '
1332
1330
f'{ len (self )} , not { len (X )} ' )
1333
1331
rgba , mask_bad = self [0 ]._get_rgba_and_mask (X [0 ], bytes = False )
1334
- rgba = np .asarray (rgba )
1335
1332
for c , xx in zip (self [1 :], X [1 :]):
1336
1333
sub_rgba , sub_mask_bad = c ._get_rgba_and_mask (xx , bytes = False )
1337
- sub_rgba = np .asarray (sub_rgba )
1338
1334
rgba [..., :3 ] += sub_rgba [..., :3 ] # add colors
1339
1335
rgba [..., 3 ] *= sub_rgba [..., 3 ] # multiply alpha
1340
1336
mask_bad |= sub_mask_bad
@@ -1418,11 +1414,10 @@ def resampled(self, lutshape):
1418
1414
1419
1415
Parameters
1420
1416
----------
1421
- lutshape : tuple of ints or None
1422
- The tuple must be of length matching the number of variates,
1423
- and each entry is either an int or None.
1424
- If an int, the corresponding colorbar is resampled.
1425
- If None, the corresponding colorbar is not resampled.
1417
+ lutshape : tuple of (`int`, `None`)
1418
+ The tuple must have a length matching the number of variates.
1419
+ For each element in the tuple, if `int`, the corresponding colorbar
1420
+ is resampled, if `None`, the corresponding colorbar is not resampled.
1426
1421
1427
1422
Returns
1428
1423
-------
@@ -1439,22 +1434,24 @@ def resampled(self, lutshape):
1439
1434
1440
1435
def with_extremes (self , * , bad = None , under = None , over = None ):
1441
1436
"""
1442
- Return a copy of the MultivarColormap, for which the colors for masked (*bad*)
1443
- values has been set and, low (*under*) and high (*over*) out-of-range values,
1444
- been set in the component colormaps. Note that *under* and *over* colors
1445
- are subject to the mixing rules determined by the *combination_mode*.
1437
+ Return a copy of the `MultivarColormap` with modified out-of-range attributes.
1438
+
1439
+ The *bad* keyword modifies the copied `MultivarColormap` while *under* and
1440
+ *over* modifies the attributes of the copied component colormaps.
1441
+ Note that *under* and *over* colors are subject to the mixing rules determined
1442
+ by the *combination_mode*.
1446
1443
1447
1444
Parameters
1448
1445
----------
1449
1446
bad : None or :mpltype:`color`
1450
1447
If Matplotlib color, the bad value is set accordingly in the copy
1451
1448
1452
- under : None or tuple of length matching the length of the MultivarColormap
1449
+ under : None or tuple of :mpltype:`color`
1453
1450
If tuple, the `under` value of each component is set with the values
1454
1451
from the tuple.
1455
1452
1456
- over : None or tuple of length matching the length of the MultivarColormap
1457
- If tuple, the `under ` value of each component is set with the values
1453
+ over : None or tuple of :mpltype:`color`
1454
+ If tuple, the `over ` value of each component is set with the values
1458
1455
from the tuple.
1459
1456
1460
1457
Returns
@@ -1527,7 +1524,6 @@ def __init__(self, N=256, M=256, shape='square', origin=(0, 0),
1527
1524
The number of RGB quantization levels along the first axis.
1528
1525
M : int
1529
1526
The number of RGB quantization levels along the second axis.
1530
- If None, M = N
1531
1527
shape: {'square', 'circle', 'ignore', 'circleignore'}
1532
1528
1533
1529
- 'square' each variate is clipped to [0,1] independently
@@ -1550,11 +1546,8 @@ def __init__(self, N=256, M=256, shape='square', origin=(0, 0),
1550
1546
self .name = name
1551
1547
self .N = int (N ) # ensure that N is always int
1552
1548
self .M = int (M )
1553
- if shape in ['square' , 'circle' , 'ignore' , 'circleignore' ]:
1554
- self ._shape = shape
1555
- else :
1556
- raise ValueError ("The shape must be a valid string, "
1557
- "'square', 'circle', 'ignore', or 'circleignore'" )
1549
+ _api .check_in_list (['square' , 'circle' , 'ignore' , 'circleignore' ], shape = shape )
1550
+ self ._shape = shape
1558
1551
self ._rgba_bad = (0.0 , 0.0 , 0.0 , 0.0 ) # If bad, don't paint anything.
1559
1552
self ._rgba_outside = (1.0 , 0.0 , 1.0 , 1.0 )
1560
1553
self ._isinit = False
@@ -1737,8 +1730,8 @@ def resampled(self, lutshape, transposed=False):
1737
1730
The tuple must be of length 2, and each entry is either an int or None.
1738
1731
1739
1732
- If an int, the corresponding axis is resampled.
1740
- - If -1, the axis is inverted
1741
1733
- If negative the corresponding axis is resampled in reverse
1734
+ - If -1, the axis is inverted
1742
1735
- If 1 or None, the corresponding axis is not resampled.
1743
1736
1744
1737
transposed : bool
@@ -1814,9 +1807,10 @@ def transposed(self):
1814
1807
1815
1808
def with_extremes (self , * , bad = None , outside = None , shape = None , origin = None ):
1816
1809
"""
1817
- Return a copy of the BivarColormap, for which the colors for masked (*bad*)
1818
- valuesand if shape = 'ignore' or 'circleignore', out-of-range *outside* values,
1819
- have been set accordingly.
1810
+ Return a copy of the `BivarColormap` with modified attributes.
1811
+
1812
+ Note that the *outside* color is only relevantif `shape` = 'ignore'
1813
+ or 'circleignore'.
1820
1814
1821
1815
Parameters
1822
1816
----------
@@ -1854,11 +1848,9 @@ def with_extremes(self, *, bad=None, outside=None, shape=None, origin=None):
1854
1848
if outside is not None :
1855
1849
new_cm ._rgba_outside = to_rgba (outside )
1856
1850
if shape is not None :
1857
- if shape in ['square' , 'circle' , 'ignore' , 'circleignore' ]:
1858
- new_cm ._shape = shape
1859
- else :
1860
- raise ValueError ("The shape must be a valid string, "
1861
- "'square', 'circle', 'ignore', or 'circleignore'" )
1851
+ _api .check_in_list (['square' , 'circle' , 'ignore' , 'circleignore' ],
1852
+ shape = shape )
1853
+ new_cm ._shape = shape
1862
1854
if origin is not None :
1863
1855
new_cm ._origin = (float (origin [0 ]), float (origin [1 ]))
1864
1856
@@ -2013,7 +2005,7 @@ def color_block(color):
2013
2005
'</div>'
2014
2006
'<div style="float: right;">'
2015
2007
f'bad { color_block (self .get_bad ())} '
2016
- '</div>' )
2008
+ '</div></div> ' )
2017
2009
2018
2010
def copy (self ):
2019
2011
"""Return a copy of the colormap."""
@@ -2051,6 +2043,7 @@ class SegmentedBivarColormap(BivarColormap):
2051
2043
2052
2044
def __init__ (self , patch , N = 256 , shape = 'square' , origin = (0 , 0 ),
2053
2045
name = 'segmented bivariate colormap' ):
2046
+ _api .check_shape ((None , None , 3 ), patch = patch )
2054
2047
self .patch = patch
2055
2048
super ().__init__ (N , N , shape , origin , name = name )
2056
2049
0 commit comments