@@ -1351,10 +1351,10 @@ def __call__(self, X, alpha=None, bytes=False, clip=True):
1351
1351
if alpha is not None :
1352
1352
if clip :
1353
1353
alpha = np .clip (alpha , 0 , 1 )
1354
- if alpha .shape not in [(), np .array (X [0 ]). shape ]:
1354
+ if np .shape ( alpha ) not in [(), np .shape (X [0 ])]:
1355
1355
raise ValueError (
1356
- f"alpha is array-like but its shape { alpha .shape } does "
1357
- f"not match that of X[0] { np .array (X [0 ]). shape } " )
1356
+ f"alpha is array-like but its shape { np .shape ( alpha ) } does "
1357
+ f"not match that of X[0] { np .shape (X [0 ])} " )
1358
1358
rgba [..., - 1 ] *= alpha
1359
1359
1360
1360
if bytes :
@@ -1385,14 +1385,14 @@ def __copy__(self):
1385
1385
def __eq__ (self , other ):
1386
1386
if not isinstance (other , MultivarColormap ):
1387
1387
return False
1388
- if not len (self ) = = len (other ):
1388
+ if len (self ) ! = len (other ):
1389
1389
return False
1390
1390
for c0 , c1 in zip (self , other ):
1391
- if not c0 = = c1 :
1391
+ if c0 ! = c1 :
1392
1392
return False
1393
1393
if not all (self ._rgba_bad == other ._rgba_bad ):
1394
1394
return False
1395
- if not self .combination_mode = = other .combination_mode :
1395
+ if self .combination_mode ! = other .combination_mode :
1396
1396
return False
1397
1397
return True
1398
1398
@@ -1430,7 +1430,7 @@ def resampled(self, lutshape):
1430
1430
MultivarColormap
1431
1431
"""
1432
1432
1433
- if not np .iterable (lutshape ) or not len (lutshape ) = = len (self ):
1433
+ if not np .iterable (lutshape ) or len (lutshape ) ! = len (self ):
1434
1434
raise ValueError (f"lutshape must be of length { len (self )} " )
1435
1435
new_cmap = self .copy ()
1436
1436
for i , s in enumerate (lutshape ):
@@ -1447,7 +1447,7 @@ def with_extremes(self, *, bad=None, under=None, over=None):
1447
1447
1448
1448
Parameters
1449
1449
----------
1450
- bad : None or Matplotlib color
1450
+ bad : None or :mpltype:` color`
1451
1451
If Matplotlib color, the bad value is set accordingly in the copy
1452
1452
1453
1453
under : None or tuple of length matching the length of the MultivarColormap
@@ -1468,17 +1468,19 @@ def with_extremes(self, *, bad=None, under=None, over=None):
1468
1468
if bad is not None :
1469
1469
new_cm ._rgba_bad = to_rgba (bad )
1470
1470
if under is not None :
1471
- if not np .iterable (under ) or not len (under ) = = len (new_cm ):
1471
+ if not np .iterable (under ) or len (under ) ! = len (new_cm ):
1472
1472
raise ValueError ("*under* must contain a color for each scalar colormap"
1473
1473
f" i.e. be of length { len (new_cm )} ." )
1474
1474
else :
1475
- [c .set_under (b ) for c , b in zip (new_cm , under )]
1475
+ for c , b in zip (new_cm , under ):
1476
+ c .set_under (b )
1476
1477
if over is not None :
1477
- if not np .iterable (over ) or not len (over ) = = len (new_cm ):
1478
+ if not np .iterable (over ) or len (over ) ! = len (new_cm ):
1478
1479
raise ValueError ("*over* must contain a color for each scalar colormap"
1479
1480
f" i.e. be of length { len (new_cm )} ." )
1480
1481
else :
1481
- [c .set_over (b ) for c , b in zip (new_cm , over )]
1482
+ for c , b in zip (new_cm , over ):
1483
+ c .set_over (b )
1482
1484
return new_cm
1483
1485
1484
1486
@property
@@ -1511,9 +1513,9 @@ def _repr_html_(self):
1511
1513
1512
1514
class BivarColormap :
1513
1515
"""
1514
- Baseclass for all bivarate to RGBA mappings.
1516
+ Base class for all bivariate to RGBA mappings.
1515
1517
1516
- Designed as a drop-in replcement for Colormap when using a 2D
1518
+ Designed as a drop-in replacement for Colormap when using a 2D
1517
1519
lookup table. To be used with `~matplotlib.cm.VectorMappable`.
1518
1520
"""
1519
1521
@@ -1527,7 +1529,7 @@ def __init__(self, N=256, M=256, shape='square', origin=(0, 0),
1527
1529
M : int
1528
1530
The number of RGB quantization levels along the second axis.
1529
1531
If None, M = N
1530
- shape: str 'square' or 'circle' or 'ignore' or 'circleignore'
1532
+ shape: { 'square', 'circle', 'ignore', 'circleignore'}
1531
1533
1532
1534
- 'square' each variate is clipped to [0,1] independently
1533
1535
- 'circle' the variates are clipped radially to the center
@@ -1594,7 +1596,7 @@ def __call__(self, X, alpha=None, bytes=False):
1594
1596
if len (X ) != 2 :
1595
1597
raise ValueError (
1596
1598
f'For a `BivarColormap` the data must have a first dimension '
1597
- f'{ 2 } , not { len (X )} ' )
1599
+ f'2 , not { len (X )} ' )
1598
1600
1599
1601
if not self ._isinit :
1600
1602
self ._init ()
@@ -1621,8 +1623,7 @@ def __call__(self, X, alpha=None, bytes=False):
1621
1623
X1 [X1 == self .M ] = self .M - 1
1622
1624
1623
1625
# Pre-compute the masks before casting to int (which can truncate)
1624
- mask_outside = (X0 < 0 ) | (X1 < 0 ) \
1625
- | (X0 >= self .N ) | (X1 >= self .M )
1626
+ mask_outside = (X0 < 0 ) | (X1 < 0 ) | (X0 >= self .N ) | (X1 >= self .M )
1626
1627
# If input was masked, get the bad mask from it; else mask out nans.
1627
1628
mask_bad_0 = X0 .mask if np .ma .is_masked (X0 ) else np .isnan (X0 )
1628
1629
mask_bad_1 = X1 .mask if np .ma .is_masked (X1 ) else np .isnan (X1 )
@@ -1650,10 +1651,10 @@ def __call__(self, X, alpha=None, bytes=False):
1650
1651
alpha = np .clip (alpha , 0 , 1 )
1651
1652
if bytes :
1652
1653
alpha *= 255 # Will be cast to uint8 upon assignment.
1653
- if alpha .shape not in [(), np .array (X0 ). shape ]:
1654
+ if np .shape ( alpha ) not in [(), np .shape (X0 )]:
1654
1655
raise ValueError (
1655
- f"alpha is array-like but its shape { alpha .shape } does "
1656
- f"not match that of X[0] { np .array (X0 ). shape } " )
1656
+ f"alpha is array-like but its shape { np .shape ( alpha ) } does "
1657
+ f"not match that of X[0] { np .shape (X0 )} " )
1657
1658
rgba [..., - 1 ] = alpha
1658
1659
# If the "bad" color is all zeros, then ignore alpha input.
1659
1660
if (np .array (self ._rgba_bad ) == 0 ).all ():
@@ -1713,7 +1714,7 @@ def __eq__(self, other):
1713
1714
return False
1714
1715
if not np .array_equal (self ._rgba_outside , other ._rgba_outside ):
1715
1716
return False
1716
- if not self .shape = = other .shape :
1717
+ if self .shape ! = other .shape :
1717
1718
return False
1718
1719
return True
1719
1720
@@ -1728,6 +1729,7 @@ def get_outside(self):
1728
1729
def resampled (self , lutshape , transposed = False ):
1729
1730
"""
1730
1731
Return a new colormap with *lutshape* entries.
1732
+
1731
1733
Note that this function does not move the origin.
1732
1734
1733
1735
Parameters
@@ -1748,7 +1750,7 @@ def resampled(self, lutshape, transposed=False):
1748
1750
BivarColormap
1749
1751
"""
1750
1752
1751
- if not np .iterable (lutshape ) or not len (lutshape ) = = 2 :
1753
+ if not np .iterable (lutshape ) or len (lutshape ) ! = 2 :
1752
1754
raise ValueError ("lutshape must be of length 2" )
1753
1755
lutshape = [lutshape [0 ], lutshape [1 ]]
1754
1756
if lutshape [0 ] is None or lutshape [0 ] == 1 :
@@ -1776,7 +1778,7 @@ def resampled(self, lutshape, transposed=False):
1776
1778
else :
1777
1779
x_1 = np .linspace (1 , 0 , lutshape [1 ])[np .newaxis , :] * np .ones (lutshape )
1778
1780
1779
- # we need to use shape = 'sqare ' while resampling the colormap.
1781
+ # we need to use shape = 'square ' while resampling the colormap.
1780
1782
# if the colormap has shape = 'circle' we would otherwise get *outside* in the
1781
1783
# resampled colormap
1782
1784
shape_memory = self ._shape
@@ -1785,7 +1787,7 @@ def resampled(self, lutshape, transposed=False):
1785
1787
new_lut = self ((x_1 , x_0 ))
1786
1788
new_cmap = BivarColormapFromImage (new_lut , name = self .name ,
1787
1789
shape = shape_memory ,
1788
- origin = ( self .origin [1 ], self . origin [ 0 ]) )
1790
+ origin = self .origin [:: - 1 ] )
1789
1791
else :
1790
1792
new_lut = self ((x_0 , x_1 ))
1791
1793
new_cmap = BivarColormapFromImage (new_lut , name = self .name ,
@@ -1801,12 +1803,8 @@ def reversed(self, axis_0=True, axis_1=True):
1801
1803
"""
1802
1804
Reverses both or one of the axis.
1803
1805
"""
1804
- r_0 = 1
1805
- if axis_0 :
1806
- r_0 = - 1
1807
- r_1 = 1
1808
- if axis_1 :
1809
- r_1 = - 1
1806
+ r_0 = - 1 if axis_0 else 1
1807
+ r_1 = - 1 if axis_1 else 1
1810
1808
return self .resampled ((r_0 , r_1 ))
1811
1809
1812
1810
def transposed (self ):
@@ -1823,22 +1821,22 @@ def with_extremes(self, *, bad=None, outside=None, shape=None, origin=None):
1823
1821
1824
1822
Parameters
1825
1823
----------
1826
- bad : None or Matplotlib color
1824
+ bad : None or :mpltype:` color`
1827
1825
If Matplotlib color, the *bad* value is set accordingly in the copy
1828
1826
1829
- outside : None or Matplotlib color
1827
+ outside : None or :mpltype:` color`
1830
1828
If Matplotlib color and shape is 'ignore' or 'circleignore', values
1831
1829
*outside* the colormap are colored accordingly in the copy
1832
1830
1833
- shape: str 'square' or 'circle' or 'ignore' or 'circleignore'
1831
+ shape : { 'square', 'circle', 'ignore', 'circleignore'}
1834
1832
1835
1833
- If 'square' each variate is clipped to [0,1] independently
1836
1834
- If 'circle' the variates are clipped radially to the center
1837
1835
of the colormap, and a circular mask is applied when the colormap
1838
1836
is displayed
1839
1837
- If 'ignore' the variates are not clipped, but instead assigned the
1840
1838
*outside* color
1841
- - If 'circleignore' a circular mask is applied, but the data is not
1839
+ - If 'circleignore' a circular mask is applied, but the data is not
1842
1840
clipped and instead assigned the *outside* color
1843
1841
1844
1842
origin: (float, float)
@@ -1890,7 +1888,7 @@ def _clip(self, X):
1890
1888
----------
1891
1889
X: np.array
1892
1890
array of floats or ints to be clipped
1893
- shape: str 'square' or 'circle' or 'ignore' or 'circleignore'
1891
+ shape : { 'square', 'circle', 'ignore', 'circleignore'}
1894
1892
1895
1893
- If 'square' each variate is clipped to [0,1] independently
1896
1894
- If 'circle' the variates are clipped radially to the center
@@ -1921,7 +1919,7 @@ def _clip(self, X):
1921
1919
1922
1920
elif self .shape == 'circle' or self .shape == 'circleignore' :
1923
1921
for X_part in X :
1924
- if not X_part .dtype .kind = = "f" :
1922
+ if X_part .dtype .kind ! = "f" :
1925
1923
raise NotImplementedError (
1926
1924
"Circular bivariate colormaps are only"
1927
1925
" implemented for use with with floats" )
@@ -1944,14 +1942,14 @@ def __getitem__(self, item):
1944
1942
if origin_1_as_int > self .M - 1 :
1945
1943
origin_1_as_int = self .M - 1
1946
1944
one_d_lut = self ._lut [:, origin_1_as_int ]
1947
- new_cmap = ListedColormap (one_d_lut , name = self .name + ' _0' , N = self .N )
1945
+ new_cmap = ListedColormap (one_d_lut , name = f' { self .name } _0' , N = self .N )
1948
1946
1949
1947
elif item == 1 :
1950
1948
origin_0_as_int = int (self ._origin [0 ]* self .N )
1951
1949
if origin_0_as_int > self .N - 1 :
1952
1950
origin_0_as_int = self .N - 1
1953
1951
one_d_lut = self ._lut [origin_0_as_int , :]
1954
- new_cmap = ListedColormap (one_d_lut , name = self .name + ' _1' , N = self .M )
1952
+ new_cmap = ListedColormap (one_d_lut , name = f' { self .name } _1' , N = self .M )
1955
1953
else :
1956
1954
raise KeyError (f"only 0 or 1 are"
1957
1955
f" valid keys for BivarColormap, not { item !r} " )
@@ -2025,15 +2023,15 @@ def copy(self):
2025
2023
2026
2024
class SegmentedBivarColormap (BivarColormap ):
2027
2025
"""
2028
- BivarColormap object generated by supersampling a regular grid
2026
+ BivarColormap object generated by supersampling a regular grid.
2029
2027
2030
2028
Parameters
2031
2029
----------
2032
- patch : nparray of shape (k, k, 3)
2033
- This patch gets supersamples to a lut of shape (N, M, 4)
2030
+ patch : np.array of shape (k, k, 3)
2031
+ This patch gets supersampled to a lut of shape (N, M, 4).
2034
2032
N : int
2035
2033
The number of RGB quantization levels along each axis.
2036
- shape: str 'square' or 'circle' or 'ignore' or 'circleignore'
2034
+ shape: { 'square', 'circle', 'ignore', 'circleignore'}
2037
2035
2038
2036
- If 'square' each variate is clipped to [0,1] independently
2039
2037
- If 'circle' the variates are clipped radially to the center
@@ -2073,13 +2071,13 @@ def _init(self):
2073
2071
2074
2072
class BivarColormapFromImage (BivarColormap ):
2075
2073
"""
2076
- BivarColormap object generated by supersampling a regular grid
2074
+ BivarColormap object generated by supersampling a regular grid.
2077
2075
2078
2076
Parameters
2079
2077
----------
2080
2078
lut : nparray of shape (N, M, 3) or (N, M, 4)
2081
2079
The look-up-table
2082
- shape: str 'square' or 'circle' or 'ignore' or 'circleignore'
2080
+ shape: { 'square', 'circle', 'ignore', 'circleignore'}
2083
2081
2084
2082
- If 'square' each variate is clipped to [0,1] independently
2085
2083
- If 'circle' the variates are clipped radially to the center
@@ -2099,7 +2097,7 @@ class BivarColormapFromImage(BivarColormap):
2099
2097
"""
2100
2098
2101
2099
def __init__ (self , lut , shape = 'square' , origin = (0 , 0 ), name = 'from image' ):
2102
- # We can allow for a PIL.Image as unput in the following way, but importing
2100
+ # We can allow for a PIL.Image as input in the following way, but importing
2103
2101
# matplotlib.image.pil_to_array() results in a circular import
2104
2102
# For now, this function only accepts numpy arrays.
2105
2103
# i.e.:
0 commit comments