qualpal.Qualpal

class qualpal.Qualpal(colors: Sequence[str] | None = None, colorspace: dict[str, tuple[float, float]] | None = None, palette: str | None = None, space: str = 'hsl', cvd: dict[str, float] | None = None, metric: str = 'ciede2000', background: str | None = None, max_memory: float = 1.0, colorspace_size: int = 1000)[source]

Bases: object

Generate qualitative color palettes with distinct colors.

The Qualpal class provides a stateful builder for generating color palettes. You can specify colors, colorspace, or palette as input, and configure parameters like CVD simulation, distance metric, etc.

Methods

generate

Generate a color palette with n distinct colors.

Attributes

background

Get background color.

colorspace_size

Get colorspace size.

cvd

Get color vision deficiency simulation settings.

max_memory

Get maximum memory in GB.

metric

Get color difference metric.

property background: str | None[source]

Get background color.

property colorspace_size: int[source]

Get colorspace size.

property cvd: dict[str, float] | None[source]

Get color vision deficiency simulation settings.

generate(n: int) Palette[source]

Generate a color palette with n distinct colors.

Parameters:

n (int) – Number of colors to generate.

Returns:

A Palette object containing n Color objects.

Return type:

Palette

Raises:
  • RuntimeError – If palette generation fails (e.g., C++ algorithm error).

  • ValueError – If n is not positive.

  • TypeError – If n is not an integer.

Notes

Behavior depends on input mode:

  • colorspace mode: Samples n colors from the continuous color space

  • colors mode: Selects n most distinct colors from the provided list

  • palette mode: Loads named palette and selects n most distinct colors

property max_memory: float[source]

Get maximum memory in GB.

property metric: str[source]

Get color difference metric.