Color Resolution Helper

GitHub Link to Code.

Shared helper for resolving user color configuration.

Handles the common colors behavior used by multiple plot types:

  • None -> use defaults

  • str -> build colors from matplotlib colormap

  • dict -> merge explicit overrides on defaults

class mdxplain.plots.helper.color_resolution_helper.ColorResolutionHelper

Shared resolver for label-to-color mappings.

Provides deterministic color assignment across plot types for the common colors API:

  • None: keep default mapping

  • str: sample colors from a matplotlib colormap

  • dict: merge explicit overrides onto defaults

static resolve_label_colors(labels: List[str], colors: str | Dict[str, str] | None = None, default_colors: Dict[str, str] | None = None) Dict[str, str]

Resolve colors for labels.

Parameters

labelsList[str]

Labels to colorize in deterministic order.

colorsstr or Dict[str, str], optional

User-provided color configuration:

  • None: use defaults

  • str: matplotlib colormap name

  • dict: explicit mapping merged onto defaults

default_colorsDict[str, str], optional

Optional base mapping used when colors is None or dict. Missing labels fall back to automatic palette colors.

Returns

Dict[str, str]

Label -> color mapping.

Raises

ValueError

If colors is not None/str/dict or if colormap name is invalid.

static build_colors_from_colormap(labels: List[str], colormap: str) Dict[str, str]

Build deterministic label colors from a matplotlib colormap.

Parameters

labelsList[str]

Labels to colorize in deterministic order.

colormapstr

Matplotlib colormap name.

Returns

Dict[str, str]

Mapping from label to hex color.

Raises

ValueError

If the colormap name is unknown to matplotlib.