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