Skip to content

Commit 08f5cbb

Browse files
committed
Colormap() converts input matplotlib cmaps to subclass
1 parent 78e454b commit 08f5cbb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

proplot/styletools.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,9 +1664,15 @@ def Colormap(*args, name=None, listmode='perceptual',
16641664
ireverse = False if not np.iterable(reverse) else reverse[i]
16651665
ileft = None if not np.iterable(left) else left[i]
16661666
iright = None if not np.iterable(right) else right[i]
1667-
# Interpret existing colormap
1668-
if isinstance(cmap, mcolors.Colormap):
1667+
# Convert matplotlib colormaps to subclasses
1668+
if isinstance(cmap, (ListedColormap, LinearSegmentedColormap)):
16691669
pass
1670+
elif type(cmap) is mcolors.LinearSegmentedColormap:
1671+
cmap = LinearSegmentedColormap(
1672+
cmap.name, cmap._segmentdata, cmap.N, cmap._gamma)
1673+
elif type(cmap) is mcolors.ListedColormap:
1674+
cmap = ListedColormap(
1675+
cmap.colors, cmap.name, cmap.N)
16701676
# Dictionary of hue/sat/luminance values or 2-tuples representing linear transition
16711677
elif isinstance(cmap, dict):
16721678
cmap = PerceptuallyUniformColormap.from_hsl(tmp, **cmap)

0 commit comments

Comments
 (0)