colorization
pleat.colorization ¶
Resolve per-element colours from color_key attributes and color_by classifiers.
A colour key is any hashable used by renderers to look up a colour. This module:
- assigns hashable colour keys onto graph elements (:func:
colorize), and - resolves those keys plus optional
color_byclassifiers into concrete RGB(A) colours using a matplotlib colormap (:func:resolve_colors).
is_color ¶
Return True if obj looks like an RGB(A) tuple/list/array of numbers or a #RRGGBB string.
Source code in pleat/colorization.py
colorize ¶
Assign face[key] = classifier.classify(face) for every face in graph.
congruency_colorize ¶
Colour faces by polygon congruence (same edge lengths and interior angles).
resolve_colors ¶
resolve_colors(
elements,
color_by,
cmap,
presets: dict[str, Callable[[], Classifier]],
key: str = "color_key",
) -> dict[Any, np.ndarray]
Compute a {element → RGBA} map for the given elements.
Resolution rules (highest priority first):
- If
element[key]is a colour literal (RGB(A) tuple / hex / array), use it as-is. - If
element[key]exists but is a non-colour hashable, treat it as a class index. - Otherwise, if color_by is set, run its classifier on the element.
- Otherwise, leave the element unassigned (the renderer applies its own fallback).
Distinct class indices are then sorted by frequency (descending; iteration order breaks ties) and assigned palette slots in that order.
If color_by is set but every element already has a key attribute, a
:class:UserWarning is emitted (the classifier had nothing to do).