@@ -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 ):
@@ -1291,9 +1291,7 @@ def __init__(self, colormaps, combination_mode, name='multivariate colormap'):
1291
1291
" Colormap or valid strings." )
1292
1292
1293
1293
self ._colormaps = colormaps
1294
- if combination_mode not in ['sRGB_add' , 'sRGB_sub' ]:
1295
- raise ValueError ("Combination_mode must be 'sRGB_add' or 'sRGB_sub',"
1296
- f" { combination_mode !r} is not allowed." )
1294
+ _api .check_in_list (['sRGB_add' , 'sRGB_sub' ], combination_mode = combination_mode )
1297
1295
self ._combination_mode = combination_mode
1298
1296
self .n_variates = len (colormaps )
1299
1297
self ._rgba_bad = (0.0 , 0.0 , 0.0 , 0.0 ) # If bad, don't paint anything.
@@ -1332,10 +1330,8 @@ def __call__(self, X, alpha=None, bytes=False, clip=True):
1332
1330
f'For the selected colormap the data must have a first dimension '
1333
1331
f'{ len (self )} , not { len (X )} ' )
1334
1332
rgba , mask_bad = self [0 ]._get_rgba_and_mask (X [0 ], bytes = False )
1335
- rgba = np .asarray (rgba )
1336
1333
for c , xx in zip (self [1 :], X [1 :]):
1337
1334
sub_rgba , sub_mask_bad = c ._get_rgba_and_mask (xx , bytes = False )
1338
- sub_rgba = np .asarray (sub_rgba )
1339
1335
rgba [..., :3 ] += sub_rgba [..., :3 ] # add colors
1340
1336
rgba [..., 3 ] *= sub_rgba [..., 3 ] # multiply alpha
1341
1337
mask_bad |= sub_mask_bad
@@ -1419,11 +1415,10 @@ def resampled(self, lutshape):
1419
1415
1420
1416
<
F438
span class=pl-s> Parameters
1421
1417
----------
1422
- lutshape : tuple of ints or None
1423
- The tuple must be of length matching the number of variates,
1424
- and each entry is either an int or None.
1425
- If an int, the corresponding colorbar is resampled.
1426
- If None, the corresponding colorbar is not resampled.
1418
+ lutshape : tuple of (`int`, `None`)
1419
+ The tuple must have a length matching the number of variates.
1420
+ For each element in the tuple, if `int`, the corresponding colorbar
1421
+ is resampled, if `None`, the corresponding colorbar is not resampled.
1427
1422
1428
1423
Returns
1429
1424
-------
@@ -1440,22 +1435,24 @@ def resampled(self, lutshape):
1440
1435
1441
1436
def with_extremes (self , * , bad = None , under = None , over = None ):
1442
1437
"""
1443
- Return a copy of the MultivarColormap, for which the colors for masked (*bad*)
1444
- values has been set and, low (*under*) and high (*over*) out-of-range values,
1445
- been set in the component colormaps. Note that *under* and *over* colors
1446
- are subject to the mixing rules determined by the *combination_mode*.
1438
+ Return a copy of the `MultivarColormap` with modified out-of-range attributes.
1439
+
1440
+ The *bad* keyword modifies the copied `MultivarColormap` while *under* and
1441
+ *over* modifies the attributes of the copied component colormaps.
1442
+ Note that *under* and *over* colors are subject to the mixing rules determined
1443
+ by the *combination_mode*.
1447
1444
1448
1445
Parameters
1449
1446
----------
1450
1447
bad : None or :mpltype:`color`
1451
1448
If Matplotlib color, the bad value is set accordingly in the copy
1452
1449
1453
- under : None or tuple of length matching the length of the MultivarColormap
1450
+ under : None or tuple of :mpltype:`color`
1454
1451
If tuple, the `under` value of each component is s
10000
et with the values
1455
1452
from the tuple.
1456
1453
1457
- over : None or tuple of length matching the length of the MultivarColormap
1458
- If tuple, the `under ` value of each component is set with the values
1454
+ over : None or tuple of :mpltype:`color`
1455
+ If tuple, the `over ` value of each component is set with the values
1459
1456
from the tuple.
1460
1457
1461
1458
Returns
@@ -1528,7 +1525,6 @@ def __init__(self, N=256, M=256, shape='square', origin=(0, 0),
1528
1525
The number of RGB quantization levels along the first axis.
1529
1526
M : int
1530
1527
The number of RGB quantization levels along the second axis.
1531
- If None, M = N
1532
1528
shape: {'square', 'circle', 'ignore', 'circleignore'}
1533
1529
1534
1530
- 'square' each variate is clipped to [0,1] independently
@@ -1551,11 +1547,8 @@ def __init__(self, N=256, M=256, shape='square', origin=(0, 0),
1551
1547
self .name = name
1552
1548
self .N = int (N ) # ensure that N is always int
1553
1549
self .M = int (M )
1554
- if shape in ['square' , 'circle' , 'ignore' , 'circleignore' ]:
1555
- self ._shape = shape
1556
- else :
1557
- raise ValueError ("The shape must be a valid string, "
1558
- "'square', 'circle', 'ignore', or 'circleignore'" )
1550
+ _api .check_in_list (['square' , 'circle' , 'ignore' , 'circleignore' ], shape = shape )
1551
+ self ._shape = shape
1559
1552
self ._rgba_bad = (0.0 , 0.0 , 0.0 , 0.0 ) # If bad, don't paint anything.
1560
1553
self ._rgba_outside = (1.0 , 0.0 , 1.0 , 1.0 )
1561
1554
self ._isinit = False
@@ -1738,8 +1731,8 @@ def resampled(self, lutshape, transposed=False):
1738
1731
The tuple must be of length 2, and each entry is either an int or None.
1739
1732
1740
1733
- If an int, the corresponding axis is resampled.
1741
- - If -1, the axis is inverted
1742
1734
- If negative the corresponding axis is resampled in reverse
1735
+ - If -1, the axis is inverted
1743
1736
- If 1 or None, the corresponding axis is not resampled.
1744
1737
1745
1738
transposed : bool
@@ -1815,9 +1808,10 @@ def transposed(self):
1815
1808
1816
1809
def with_extremes (self , * , bad = None , outside = None , shape = None , origin = None ):
1817
1810
"""
1818
- Return a copy of the BivarColormap, for which the colors for masked (*bad*)
1819
- valuesand if shape = 'ignore' or 'circleignore', out-of-range *outside* values,
1820
- have been set accordingly.
1811
+ Return a copy of the `BivarColormap` with modified attributes.
1812
+
1813
+ Note that the *outside* color is only relevantif `shape` = 'ignore'
1814
+ or 'circleignore'.
1821
1815
1822
1816
Parameters
1823
1817
----------
@@ -1855,11 +1849,9 @@ def with_extremes(self, *, bad=None, outside=None, shape=None, origin=None):
1855
1849
if outside is not None :
1856
1850
new_cm ._rgba_outside = to_rgba (outside )
1857
1851
if shape is not None :
1858
- if shape in ['square' , 'circle' , 'ignore' , 'circleignore' ]:
1859
- new_cm ._shape = shape
1860
- else :
1861
- raise ValueError ("The shape must be a valid string, "
1862
- "'square', 'circle', 'ignore', or 'circleignore'" )
1852
+ _api .check_in_list (['square' , 'circle' , 'ignore' , 'circleignore' ],
1853
+ shape = shape )
1854
+ new_cm ._shape = shape
1863
1855
if origin is not None :
1864
1856
new_cm ._origin = (float (origin [0 ]), float (origin [1 ]))
1865
1857
@@ -2014,7 +2006,7 @@ def color_block(color):
2014
2006
'</div>'
2015
2007
'<div style="float: right;">'
2016
2008
f'bad { color_block (self .get_bad ())} '
2017
- '</div>' )
2009
+ '</div></div> ' )
2018
2010
2019
2011
def copy (self ):
2020
2012
"""Return a copy of the colormap."""
@@ -2052,6 +2044,7 @@ class SegmentedBivarColormap(BivarColormap):
2052
2044
2053
2045
def __init__ (self , patch , N = 256 , shape = 'square' , origin = (0 , 0 ),
2054
2046
name = 'segmented bivariate colormap' ):
2047
+ _api .check_shape ((None , None , 3 ), patch = patch )
2055
2048
self .patch = patch
2056
2049
super ().__init__ (N , N , shape , origin , name = name )
2057
2050
0 commit comments