@@ -669,6 +669,67 @@ def replace_flow_block(match):
669669 "#ffff99" ,
670670 "#b15928" ,
671671 ],
672+ # Standard matplotlib continuous colormaps (hardcoded so they work without matplotlib installed)
673+ "viridis" : [
674+ "#440154" ,
675+ "#482878" ,
676+ "#3e4989" ,
677+ "#31688e" ,
678+ "#26828e" ,
679+ "#1f9e89" ,
680+ "#35b779" ,
681+ "#6ece58" ,
682+ "#b5de2b" ,
683+ "#fde725" ,
684+ ],
685+ "plasma" : [
686+ "#0d0887" ,
687+ "#46039f" ,
688+ "#7201a8" ,
689+ "#9c179e" ,
690+ "#bd3786" ,
691+ "#d8576b" ,
692+ "#ed7953" ,
693+ "#fb9f3a" ,
694+ "#fdca26" ,
695+ "#f0f921" ,
696+ ],
697+ "inferno" : [
698+ "#000004" ,
699+ "#1b0c41" ,
700+ "#4a0c6b" ,
701+ "#781c6d" ,
702+ "#a52c60" ,
703+ "#cf4446" ,
704+ "#ed6925" ,
705+ "#fb9b06" ,
706+ "#f7d13d" ,
707+ "#fcffa4" ,
708+ ],
709+ "magma" : [
710+ "#000004" ,
711+ "#180f3d" ,
712+ "#440f76" ,
713+ "#721f81" ,
714+ "#9e2f7f" ,
715+ "#cd4071" ,
716+ "#f1605d" ,
717+ "#fd9668" ,
718+ "#feca8d" ,
719+ "#fcfdbf" ,
720+ ],
721+ "cividis" : [
722+ "#00224e" ,
723+ "#123570" ,
724+ "#3b496c" ,
725+ "#575d6d" ,
726+ "#707173" ,
727+ "#8a8678" ,
728+ "#a59c74" ,
729+ "#c3b369" ,
730+ "#e1cc55" ,
731+ "#fee838" ,
732+ ],
672733}
673734
674735CDL_FONT_FAMILY = "Avenir LT Std, Avenir, Avenir Next, -apple-system, BlinkMacSystemFont, sans-serif"
@@ -701,18 +762,22 @@ def _get_palette(name: str, n_colors: "int | None" = None) -> list:
701762 return [palette [i % len (palette )] for i in range (n_colors )]
702763 return palette
703764
704- # Try matplotlib continuous colormaps (viridis, plasma, inferno, magma, cividis, etc. )
765+ # Try matplotlib continuous colormaps for names not in _PALETTES (e.g. user-specified custom cmaps )
705766 try :
767+ import matplotlib
706768 import matplotlib .colors as mcolors
707- import matplotlib .pyplot as plt
708769
709770 cmap = None
710771 for cmap_name in (name , key ):
711772 try :
712- cmap = plt .colormaps [cmap_name ]
773+ cmap = matplotlib .colormaps [cmap_name ]
713774 break
714- except (KeyError , ValueError ):
715- continue
775+ except (KeyError , ValueError , AttributeError ):
776+ try :
777+ cmap = matplotlib .cm .get_cmap (cmap_name )
778+ break
779+ except (ValueError , AttributeError ):
780+ pass
716781 if cmap is not None :
717782 count = n_colors if n_colors and n_colors > 0 else 10
718783 return [mcolors .to_hex (cmap (i / max (count - 1 , 1 ))) for i in range (count )]
0 commit comments