Commit dbaac8e
Add make_palette and make_palette_from_data for palette generation (#210)
Add two public functions for generating categorical color palettes:
- `make_palette(n)`: produce n colors from a source palette, optionally
reordered for maximum perceptual contrast or colorblind accessibility.
- `make_palette_from_data(sdata, element, color)`: like make_palette but
derives categories from a SpatialData element and supports spatially-
aware assignment (spaco-inspired) that maximizes contrast between
spatially interleaved categories.
Both functions share the same method vocabulary: "default", "contrast",
"colorblind", "protanopia", "deuteranopia", "tritanopia" (non-spatial),
plus "spaco", "spaco_colorblind", "spaco_protanopia", etc. (spatial,
only in make_palette_from_data).
The palette parameter accepts None (scanpy defaults), named palettes
("okabe_ito"), matplotlib colormap names ("tab10"), or explicit color
lists.
Also adds dict[str, str] palette support to render_shapes,
render_points, and render_labels, enabling reuse of generated palettes
across multiple render calls.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent e8c262e commit dbaac8e
6 files changed
Lines changed: 1146 additions & 24 deletions
File tree
- src/spatialdata_plot/pl
- tests/pl
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
0 commit comments