@@ -1259,12 +1259,10 @@ class MultivarColormap:
1259
1259
Class for holding multiple `~matplotlib.colors.Colormap` for use in a
1260
1260
`~matplotlib.cm.VectorMappable` object
1261
1261
"""
1262
- def __init__ (self , name , colormaps , combination_mode ):
1262
+ def __init__ (self , colormaps , combination_mode , name = 'multivariate colormap' ):
1263
1263
"""
1264
1264
Parameters
1265
1265
----------
1266
- name : str
1267
- The name of the colormap family.
1268
1266
colormaps: list or tuple of `~matplotlib.colors.Colormap` objects
1269
1267
The individual colormaps that are combined
1270
1268
combination_mode: str, 'sRGB_add' or 'sRGB_sub'
@@ -1274,6 +1272,8 @@ def __init__(self, name, colormaps, combination_mode):
1274
1272
`sRGB = cmap[0][X[0]] + cmap[1][x[1]] + ... + cmap[n-1][x[n-1]]`
1275
1273
- If 'sRGB_sub' -> Mixing produces darker colors
1276
1274
`sRGB = cmap[0][X[0]] + cmap[1][x[1]] + ... + cmap[n-1][x[n-1]] - n + 1`
1275
+ name : str, optional
1276
+ The name of the colormap family.
1277
1277
"""
1278
1278
self .name = name
1279
1279
@@ -1283,12 +1283,11 @@ def __init__(self, name, colormaps, combination_mode):
1283
1283
raise ValueError ("A MultivarColormap must have more than one colormap." )
1284
1284
colormaps = list (colormaps ) # ensure cmaps is a list, i.e. not a tuple
1285
1285
for i , cmap in enumerate (colormaps ):
1286
- if not isinstance (cmap , Colormap ):
1287
- if isinstance (cmap , str ):
1288
- colormaps [i ] = mpl .colormaps [cmap ]
1289
- else :
1290
- raise ValueError ("colormaps must be a list of objects that subclass"
1291
- " Colormap or valid strings." )
1286
+ if isinstance (cmap , str ):
1287
+ colormaps [i ] = mpl .colormaps [cmap ]
1288
+ elif not isinstance (cmap , Colormap ):
1289
+ raise ValueError ("colormaps must be a list of objects that subclass"
1290
+ " Colormap or valid strings." )
1292
1291
1293
1292
self ._colormaps = colormaps
1294
1293
if combination_mode not in ['sRGB_add' , 'sRGB_sub' ]:
@@ -1313,7 +1312,7 @@ def __call__(self, X, alpha=None, bytes=False, clip=True):
1313
1312
self[i] is colormap i.
1314
1313
alpha : float or array-like or None
1315
1314
Alpha must be a scalar between 0 and 1, a sequence of such
1316
- floats with shape matching Xi , or None.
1315
+ floats with shape matching *Xi* , or None.
1317
1316
bytes : bool
1318
1317
If False (default), the returned RGBA values will be floats in the
1319
1318
interval ``[0, 1]`` otherwise they will be `numpy.uint8`\s in the
@@ -1472,15 +1471,13 @@ def with_extremes(self, *, bad=None, under=None, over=None):
1472
1471
raise ValueError ("*under* must contain a color for each scalar colormap"
1473
1472
f" i.e. be of length { len (new_cm )} ." )
1474
1473
else :
1475
- for c , b in zip (new_cm , under ):
1476
- c .set_under (b )
1474
+ [c .set_under (b ) for c , b in zip (new_cm , under )]
1477
1475
if over is not None :
1478
1476
if not np .iterable (over ) or not len (over ) == len (new_cm ):
1479
1477
raise ValueError ("*over* must contain a color for each scalar colormap"
1480
1478
f" i.e. be of length { len (new_cm )} ." )
1481
1479
else :
1482
- for c , b in zip (new_cm , over ):
1483
- c .set_over (b )
1480
+ [c .set_over (b ) for c , b in zip (new_cm , over )]
1484
1481
return new_cm
1485
1482
1486
1483
@property
@@ -1519,32 +1516,33 @@ class BivarColormap:
1519
1516
lookup table. To be used with `~matplotlib.cm.VectorMappable`.
1520
1517
"""
1521
1518
1522
- def __init__ (self , name , N = 256 , M = 256 , shape = 'square' , origin = (0 , 0 )):
1519
+ def __init__ (self , N = 256 , M = 256 , shape = 'square' , origin = (0 , 0 ),
1520
+ name = 'bivariate colormap' ):
1523
1521
"""
1524
1522
Parameters
1525
1523
----------
1526
- name : str
1527
- The name of the colormap.
1528
1524
N : int
1529
1525
The number of RGB quantization levels along the first axis.
1530
1526
M : int
1531
1527
The number of RGB quantization levels along the second axis.
1532
1528
If None, M = N
1533
1529
shape: str 'square' or 'circle' or 'ignore' or 'circleignore'
1534
1530
1535
- - If 'square' each variate is clipped to [0,1] independently
1536
- - If 'circle' the variates are clipped radially to the center
1531
+ - 'square' each variate is clipped to [0,1] independently
1532
+ - 'circle' the variates are clipped radially to the center
1537
1533
of the colormap, and a circular mask is applied when the colormap
1538
1534
is displayed
1539
- - If 'ignore' the variates are not clipped, but instead assigned the
1535
+ - 'ignore' the variates are not clipped, but instead assigned the
1540
1536
'outside' color
1541
- - If 'circleignore' a circular mask is applied, but the data is not
1537
+ - 'circleignore' a circular mask is applied, but the data is not
1542
1538
clipped and instead assigned the 'outside' color
1543
1539
1544
1540
origin: (float, float)
1545
1541
The relative origin of the colormap. Typically (0, 0), for colormaps
1546
1542
that are linear on both axis, and (.5, .5) for circular colormaps.
1547
1543
Used when getting 1D colormaps from 2D colormaps.
1544
+ name : str, optional
1545
+ The name of the colormap.
1548
1546
"""
1549
1547
1550
1548
self .name = name
@@ -1864,7 +1862,7 @@ def with_extremes(self, *, bad=None, outside=None, shape=None, origin=None):
1864
1862
raise ValueError ("The shape must be a valid string, "
1865
1863
"'square', 'circle', 'ignore', or 'circleignore'" )
1866
1864
if origin is not None :
1867
- self ._origin = (float (origin [0 ]), float (origin [1 ]))
1865
+ new_cm ._origin = (float (origin [0 ]), float (origin [1 ]))
1868
1866
1869
1867
return new_cm
1870
1868
@@ -1941,17 +1939,17 @@ def __getitem__(self, item):
1941
1939
if not self ._isinit :
1942
1940
self ._init ()
1943
1941
if item == 0 :
1944
- o = int (self ._origin [1 ]* self .M )
1945
- if o > self .M - 1 :
1946
- o = self .M - 1
1947
- one_d_lut = self ._lut [:, o ]
1942
+ origin_1_as_int = int (self ._origin [1 ]* self .M )
1943
+ if origin_1_as_int > self .M - 1 :
1944
+ origin_1_as_int = self .M - 1
1945
+ one_d_lut = self ._lut [:, origin_1_as_int ]
1948
1946
new_cmap = ListedColormap (one_d_lut , name = self .name + '_0' , N = self .N )
1949
1947
1950
1948
elif item == 1 :
1951
- o = int (self ._origin [0 ]* self .N )
1952
- if o > self .N - 1 :
1953
- o = self .N - 1
1954
- one_d_lut = self ._lut [o , :]
1949
+ origin_0_as_int = int (self ._origin [0 ]* self .N )
1950
+ if origin_0_as_int > self .N - 1 :
1951
+ origin_0_as_int = self .N - 1
1952
+ one_d_lut = self ._lut [origin_0_as_int , :]
1955
1953
new_cmap = ListedColormap (one_d_lut , name = self .name + '_1' , N = self .M )
1956
1954
else :
1957
1955
raise KeyError (f"only 0 or 1 are"
@@ -2032,8 +2030,6 @@ class SegmentedBivarColormap(BivarColormap):
2032
2030
----------
2033
2031
patch : nparray of shape (k, k, 3)
2034
2032
This patch gets supersamples to a lut of shape (N, M, 4)
2035
- name : str
2036
- The name of the colormap.
2037
2033
N : int
2038
2034
The number of RGB quantization levels along each axis.
2039
2035
shape: str 'square' or 'circle' or 'ignore' or 'circleignore'
@@ -2051,11 +2047,14 @@ class SegmentedBivarColormap(BivarColormap):
2051
2047
that are linear on both axis, and (.5, .5) for circular colormaps.
2052
2048
Used when getting 1D colormaps from 2D colormaps.
2053
2049
2050
+ name : str, optional
2051
+ The name of the colormap.
2054
2052
"""
2055
2053
2056
- def __init__ (self , patch , name , N = 256 , shape = 'square' , origin = (0 , 0 )):
2054
+ def __init__ (self , patch , N = 256 , shape = 'square' , origin = (0 , 0 ),
2055
+ name = 'segmented bivariate colormap' ):
2057
2056
self .patch = patch
2058
- super ().__init__ (name , N , N , shape , origin )
2057
+ super ().__init__ (N , N , shape , origin , name = name )
2059
2058
2060
2059
def _init (self ):
2061
2060
s = self .patch .shape
@@ -2079,8 +2078,6 @@ class BivarColormapFromImage(BivarColormap):
2079
2078
----------
2080
2079
lut : nparray of shape (N, M, 3) or (N, M, 4)
2081
2080
The look-up-table
2082
- name : str
2083
- The name of the colormap.
2084
2081
shape: str 'square' or 'circle' or 'ignore' or 'circleignore'
2085
2082
2086
2083
- If 'square' each variate is clipped to [0,1] independently
@@ -2095,10 +2092,12 @@ class BivarColormapFromImage(BivarColormap):
2095
2092
The relative origin of the colormap. Typically (0, 0), for colormaps
2096
2093
that are linear on both axis, and (.5, .5) for circular colormaps.
2097
2094
Used when getting 1D colormaps from 2D colormaps.
2095
+ name : str, optional
2096
+ The name of the colormap.
2098
2097
2099
2098
"""
2100
2099
2101
- def __init__ (self , lut , name = '' , shape = 'square' , origin = (0 , 0 )):
2100
+ def __init__ (self , lut , shape = 'square' , origin = (0 , 0 ), name = 'from image' ):
2102
2101
# We can allow for a PIL.Image as unput in the following way, but importing
2103
2102
# matplotlib.image.pil_to_array() results in a circular import
2104
2103
# For now, this function only accepts numpy arrays.
@@ -2118,7 +2117,7 @@ def __init__(self, lut, name='', shape='square', origin=(0, 0)):
2118
2117
new_lut [:, :, 3 ] = 1.
2119
2118
lut = new_lut
2120
2119
self ._lut = lut
2121
- super ().__init__ (name , lut .shape [0 ], lut .shape [1 ], shape , origin )
2120
+ super ().__init__ (lut .shape [0 ], lut .shape [1 ], shape , origin , name = name )
2122
2121
2123
2122
def _init (self ):
2124
2123
self ._isinit = True
0 commit comments