@@ -70,7 +70,9 @@ def colormap_from_single_color(
7070 return cmap
7171
7272
73- def palette (states : list [int ]) -> list [list [float ]]:
73+ def palette (
74+ states : list [int ], cmaps : list [mpl .colors .LinearSegmentedColormap ] = None
75+ ) -> list [list [float ]]:
7476 """Colour palette.
7577
7678 The product of the states gives the number of scenarios. For each
@@ -80,19 +82,29 @@ def palette(states: list[int]) -> list[list[float]]:
8082 ----------
8183 states : list of int
8284 List of possible states for the considered parameter.
83-
85+ cmaps : list of LinearSegmentedColormap
86+ List of colormaps. Must have the same number of colormaps as the number
87+ of first level of states.
8488 Returns
8589 -------
86- palette : list of int of size (n, 4)
87- List of colours corresponding to scenarios.
90+ palette : list of float of size (n, 4)
91+ List of colors corresponding to scenarios. RGBA formatted .
8892 """
93+ n_cmaps = states [0 ]
94+ if cmaps is None :
95+ cmaps = [mpl .colormaps [cmap ] for cmap in SEQUENTIAL_PALETTES [:n_cmaps ]]
96+ else :
97+ if len (cmaps ) != cmaps :
98+ raise ValueError (
99+ "Must have the same number of cmaps as the number of first states"
100+ )
101+
89102 colors = []
90103 # one palette per first level state, could use more palette when there are
91104 # many levels
92105 n_shades = int (np .prod (states [1 :]))
93- for i in range (states [0 ]):
94- palette_ = SEQUENTIAL_PALETTES [i ]
95- cmap = mpl .colormaps [palette_ ].resampled (n_shades + 1 )
106+ for i in range (n_cmaps ):
107+ cmap = cmaps [i ].resampled (n_shades + 1 )
96108 colors .append (cmap (range (1 , n_shades + 1 )))
97109
98110 return np .concatenate (colors ).tolist ()
0 commit comments