qualpal.Qualpal
Python · python · 1.1.0
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.
__init__
Source: qualpal/qualpal.py
-> NoneInitialize Qualpal object.
Parameters
colors : Sequence[str] | None
List of hex color strings to use as starting point. Mutually exclusive with colorspace and palette.
colorspace : dict[str, tuple[float, float]] | None
Colorspace specification with ranges for each dimension. Keys depend on ‘space’ parameter: - ‘hsl’: ‘h’, ‘s’, ‘l’ - ‘lchab’: ‘h’, ‘c’, ‘l’ Each value is a (min, max) tuple. Mutually exclusive with colors and palette.
palette : str | None
Named palette in format ‘source:name’ (e.g., ‘ColorBrewer:Set1’). Mutually exclusive with colors and colorspace.
space : str
Color space to use: ‘hsl’ (default) or ‘lchab’.
cvd : dict[str, float] | None
Color vision deficiency simulation. Keys: ‘protan’, ‘deutan’, ‘tritan’. Values: 0.0 (normal) to 1.0 (complete deficiency).
metric : str
Color difference metric: ‘ciede2000’ (default), ‘din99d’, or ‘cie76’.
background : str | None
Background color as hex string (e.g., ‘#ffffff’).
max_memory : float
Maximum memory to use in GB (default: 1.0).
colorspace_size : int
Number of colors to sample from colorspace (default: 1000).
Raises
ValueErrorIf multiple of colors/colorspace/palette are provided, or if any parameter has invalid values.
TypeErrorIf parameter types are incorrect.
cvd
Source: qualpal/qualpal.py
-> | NoneGet color vision deficiency simulation settings.
metric
Source: qualpal/qualpal.py
-> Get color difference metric.
background
Source: qualpal/qualpal.py
-> | NoneGet background color.
max_memory
Source: qualpal/qualpal.py
-> Get maximum memory in GB.
colorspace_size
Source: qualpal/qualpal.py
-> Get colorspace size.
generate
Source: qualpal/qualpal.py
-> Generate a color palette with n distinct colors.
Parameters
n : int
Number of colors to generate.
Returns
Palette
A Palette object containing n Color objects.
Raises
RuntimeErrorIf palette generation fails (e.g., C++ algorithm error).
ValueErrorIf n is not positive.
TypeErrorIf 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
