@@ -657,7 +657,8 @@ def append(self, *args, ratios=None, name=None, N=None, **kwargs):
657
657
# PerceptuallyUniformColormap --> LinearSegmentedColormap conversions
658
658
cmaps = [self , * args ]
659
659
spaces = {getattr (cmap , '_space' , None ) for cmap in cmaps }
660
- if len (spaces ) > 1 : # mixed colorspaces *or* mixed types
660
+ to_linear_segmented = len (spaces ) > 1 # mixed colorspaces *or* mixed types
661
+ if to_linear_segmented :
661
662
for i , cmap in enumerate (cmaps ):
662
663
if isinstance (cmap , PerceptuallyUniformColormap ):
663
664
cmaps [i ] = cmap .to_linear_segmented ()
@@ -672,7 +673,7 @@ def append(self, *args, ratios=None, name=None, N=None, **kwargs):
672
673
ratios = np .asarray (ratios ) / np .sum (ratios )
673
674
x0 = np .append (0 , np .cumsum (ratios )) # coordinates for edges
674
675
xw = x0 [1 :] - x0 [:- 1 ] # widths between edges
675
- for key in self ._segmentdata .keys ():
676
+ for key in cmaps [ 0 ] ._segmentdata .keys (): # not self._segmentdata
676
677
# Callable segments
677
678
# WARNING: If just reference a global 'funcs' list from inside the
678
679
# 'data' function it can get overwritten in this loop. Must
@@ -688,6 +689,7 @@ def xyy(ix, funcs=funcs):
688
689
idx = max (np .searchsorted (x0 , jx ) - 1 , 0 )
689
690
kx .flat [j ] = funcs [idx ]((jx - x0 [idx ]) / xw [idx ])
690
691
return kx
692
+
691
693
# Concatenate segment arrays and make the transition at the
692
694
# seam instant so we *never interpolate* between end colors
693
695
# of different maps.
@@ -702,11 +704,13 @@ def xyy(ix, funcs=funcs):
702
704
datas [i + 1 ] = datas [i + 1 ][1 :, :]
703
705
xyy = np .concatenate (datas , axis = 0 )
704
706
xyy [:, 0 ] = xyy [:, 0 ] / xyy [:, 0 ].max (axis = 0 ) # fix fp errors
707
+
705
708
else :
706
709
raise TypeError (
707
710
'Mixed callable and non-callable colormap values.'
708
711
)
709
712
segmentdata [key ] = xyy
713
+
710
714
# Handle gamma values
711
715
if key == 'saturation' :
712
716
ikey = 'gamma1'
@@ -717,6 +721,7 @@ def xyy(ix, funcs=funcs):
717
721
if ikey in kwargs :
718
722
continue
719
723
gamma = []
724
+
720
725
for cmap in cmaps :
721
726
igamma = getattr (cmap , '_' + ikey )
722
727
if not np .iterable (igamma ):
@@ -725,6 +730,7 @@ def xyy(ix, funcs=funcs):
725
730
else :
726
731
igamma = (len (cmap ._segmentdata [key ]) - 1 ) * [igamma ]
727
732
gamma .extend (igamma )
733
+
728
734
if all (callable_ ):
729
735
if any (igamma != gamma [0 ] for igamma in gamma [1 :]):
730
736
warnings ._warn_proplot (
@@ -733,10 +739,14 @@ def xyy(ix, funcs=funcs):
733
739
f'gamma of { gamma [0 ]} .'
734
740
)
735
741
gamma = gamma [0 ]
742
+
736
743
kwargs [ikey ] = gamma
737
744
738
- # Return copy
739
- return self .copy (name = name , segmentdata = segmentdata , N = N , ** kwargs )
745
+ # Return copy or merge mixed types
746
+ if to_linear_segmented and isinstance (self , PerceptuallyUniformColormap ):
747
+ return LinearSegmentedColormap (name , segmentdata , N , ** kwargs )
748
+ else :
749
+ return self .copy (name , segmentdata , N , ** kwargs )
740
750
741
751
def cut (self , cut = None , name = None , left = None , right = None , ** kwargs ):
742
752
"""
@@ -1538,7 +1548,7 @@ def to_linear_segmented(self, **kwargs):
1538
1548
if not self ._isinit :
1539
1549
self ._init ()
1540
1550
return LinearSegmentedColormap .from_list (
1541
- self .name , self ._lut , ** kwargs
1551
+ self .name , self ._lut [: - 3 , :] , ** kwargs
1542
1552
)
1543
1553
1544
1554
@classmethod
@@ -2280,6 +2290,8 @@ def __setitem__(self, key, item):
2280
2290
item = ListedColormap (
2281
2291
item .colors , item .name , item .N
2282
2292
)
2293
+ elif isinstance (item , mcolors .Colormap ): # base class
2294
+ pass
2283
2295
else :
2284
2296
raise ValueError (
2285
2297
f'Invalid colormap { item } . Must be instance of '
0 commit comments