@@ -109,6 +109,12 @@ class Colormap:
109109 the matplotlib docs for more.
110110 - a `Callable` that takes an array of N values in the range [0, 1] and returns
111111 an (N, 4) array of RGBA values in the range [0, 1].
112+ cmap_kwargs : dict[str, Any] | None
113+ Keyword arguments to pass to the colormap function when `value` is a
114+ registered colormap name that maps to a callable function. For example:
115+ `Colormap("cubehelix", cmap_kwargs={"start": 1.0, "rotation": -1.0})`.
116+ If provided when `value` does not resolve to a callable colormap function, a
117+ `TypeError` will be raised.
112118 name : str | None
113119 A name for the colormap. If None, will be set to the identifier or the string
114120 `"custom colormap"`.
@@ -129,6 +135,14 @@ class Colormap:
129135 The color to use for values above the colormap's range.
130136 bad : ColorLike | None
131137 The color to use for bad (NaN, inf) values.
138+
139+ Raises
140+ ------
141+ TypeError
142+ If `cmap_kwargs` is provided and `value` does not resolve to a callable
143+ colormap function.
144+ ValueError
145+ If `value` is a string colormap name that is not found in the catalog.
132146 """
133147
134148 __slots__ = (
@@ -226,6 +240,7 @@ def __init__(
226240 under : ColorLike | None = None ,
227241 over : ColorLike | None = None ,
228242 bad : ColorLike | None = None ,
243+ cmap_kwargs : dict [str , Any ] | None = None ,
229244 ) -> None :
230245 self .info : CatalogItem | None = None
231246
@@ -238,6 +253,14 @@ def __init__(
238253 under = info .under if under is None else under
239254 bad = info .bad if bad is None else bad
240255 self .info = info
256+
257+ # Check if cmap_kwargs is provided for a non-callable colormap
258+ if cmap_kwargs and not callable (info .data ):
259+ raise TypeError (
260+ f"Cannot apply cmap_kwargs to colormap { info .name !r} : "
261+ "colormap is not a parametrized callable"
262+ )
263+
241264 if isinstance (info .data , list ):
242265 if not info .data : # pragma: no cover
243266 raise ValueError (f"Catalog colormap { info .name !r} has no data" )
@@ -252,7 +275,12 @@ def __init__(
252275 f"Invalid catalog colormap data for { info .name !r} : { info .data } "
253276 )
254277 else :
255- stops = _parse_colorstops (info .data )
278+ _data : ColormapLike
279+ if cmap_kwargs :
280+ _data = partial (cast ("Callable" , info .data ), ** cmap_kwargs )
281+ else :
282+ _data = info .data
283+ stops = _parse_colorstops (_data )
256284 if interpolation is None :
257285 interpolation = info .interpolation
258286 if rev :
0 commit comments