@@ -1173,10 +1173,42 @@ def save_fig(
11731173 fig .savefig (path , ** kwargs )
11741174
11751175
1176- def _get_linear_colormap (colors : list [str ], background : str ) -> list [LinearSegmentedColormap ]:
1176+ def _get_linear_colormap2 (colors : list [str ], background : str ) -> list [LinearSegmentedColormap ]:
11771177 return [LinearSegmentedColormap .from_list (c , [background , c ], N = 256 ) for c in colors ]
11781178
11791179
1180+ def _get_linear_colormap (
1181+ colors : list [str ],
1182+ background : str = "black" ,
1183+ ) -> list [LinearSegmentedColormap ]:
1184+ """
1185+ Create one LinearSegmentedColormap per color in `colors` that
1186+ fades from `background` → the color.
1187+
1188+ If background is "transparent" (or "none"), the start point
1189+ will be the same RGB as the target color but with alpha=0.
1190+ """
1191+ cmaps : list [LinearSegmentedColormap ] = []
1192+ for c in colors :
1193+ # fully opaque target
1194+ target_rgba = to_rgba (c , alpha = 1.0 )
1195+
1196+ if background .lower () in ("transparent" , "none" ):
1197+ # start with same RGB, but zero alpha
1198+ start_rgba = (target_rgba [0 ], target_rgba [1 ], target_rgba [2 ], 0.0 )
1199+ else :
1200+ # start from a solid background color
1201+ start_rgba = to_rgba (background )
1202+
1203+ cm = LinearSegmentedColormap .from_list (
1204+ f"{ c } _fade" ,
1205+ [start_rgba , target_rgba ],
1206+ N = 256 ,
1207+ )
1208+ cmaps .append (cm )
1209+
1210+ return cmaps
1211+
11801212def _get_listed_colormap (color_dict : dict [str , str ]) -> ListedColormap :
11811213 sorted_labels = sorted (color_dict .keys ())
11821214 colors = [color_dict [k ] for k in sorted_labels ]
0 commit comments