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:
objectGenerate 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 a color palette with n distinct colors.
Attributes
Get background color.
Get colorspace size.
Get color vision deficiency simulation settings.
Get maximum memory in GB.
Get color difference metric.
- 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:
- 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