Skip to content

Commit dbaac8e

Browse files
timtreisclaude
andcommitted
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from ._palette import make_palette, make_palette_from_data
12
from .basic import PlotAccessor
23

34
__all__ = [
45
"PlotAccessor",
6+
"make_palette",
7+
"make_palette_from_data",
58
]

0 commit comments

Comments
 (0)