qualpal.Palette
Python · python · 1.1.0
A collection of colors that behaves like a list.
Palette objects are immutable.
__init__
Source: qualpal/palette.py
-> NoneCreate a Palette from a list of colors.
Parameters
colors : Sequence[Color | str]
Sequence of Color objects or hex strings
Raises
ValueErrorIf any color is invalid
hex
Source: qualpal/palette.py
-> Get list of hex color strings.
Returns
list[str]
List of hex strings in format #rrggbb (lowercase)
rgb
Source: qualpal/palette.py
-> Get RGB values as list of tuples.
Returns
list[tuple[float, float, float]]
List of RGB tuples in range [0.0, 1.0]
to_css
Source: qualpal/palette.py
-> Export palette as CSS custom properties (CSS variables).
Parameters
prefix : str
Prefix for CSS variable names (default: ‘color’)
Returns
list[str]
List of CSS custom property declarations
Examples
>>>
>>> =
>>>
>>>
to_json
Source: qualpal/palette.py
-> Export palette as JSON array of hex colors.
Returns
str
JSON string containing array of hex color strings
Examples
>>>
>>> =
>>>
show
Source: qualpal/palette.py
-> Display palette as color swatches (requires matplotlib).
Parameters
labels : bool | list[str] | None) –
None (default): No labels
True: Show hex codes as labels
list[str]: Custom labels for each color
Returns
matplotlib.figure.Figure
Matplotlib Figure object that can be saved or further customized
Raises
ImportErrorIf matplotlib is not installed
Examples
>>>
>>> =
>>> = # Display swatches
>>> = # With hex codes
>>> = # Custom labels
>>> # Save to filedistance_matrix
Source: qualpal/palette.py
-> Calculate pairwise distance matrix for all colors in the palette.
Parameters
metric : str
Distance metric to use. Options: - ‘ciede2000’ (default): CIEDE2000 metric - ‘din99d’: DIN99d metric - ‘cie76’: CIE76 (Euclidean distance in Lab space)
Returns
list[list[float]]
Symmetric distance matrix where element [i][j] is the distance between colors i and j. Diagonal elements are 0.0.
Examples
>>>
>>> =
>>> =
>>>
3
>>> # Distance to self
0.0min_distance
Source: qualpal/palette.py
-> Get the minimum pairwise distance between any two colors.
Parameters
metric : str
Distance metric to use (default: ‘ciede2000’)
Returns
float
Minimum distance between any pair of distinct colors
Examples
>>>
>>> =
>>> =
>>> > 0
Truemin_distances
Source: qualpal/palette.py
-> Get minimum distance for each color to its nearest neighbor.
Parameters
metric : str
Distance metric to use (default: ‘ciede2000’)
Returns
list[float]
List where element i is the minimum distance from color i to any other color in the palette
Examples
>>>
>>> =
>>> =
>>>
3
>>>
True