pycea.get.palette#
- pycea.get.palette(tdata, key, custom=None, cmap=None, priors=None, sort=None, random_state=None)#
Get color palette for a given key.
This function gets the mapping from category → color for a given key in
tdata. If no customizations are provided, the function will return a previously stored palette intdata.unsif it exists. Otherwise, a new palette is generated.- Parameters:
tdata (
TreeData) – Thetreedata.TreeDataobject.key (
str) – A key fromobs.keys(),obsm.keys(), orobsp.keys()to generate a color palette for.custom (
Mapping[Any,Any] |None(default:None)) – A dictionary mapping specific values to colors (e.g.,{"category1": "red"}).cmap (
str|Colormap|Cycler|None(default:None)) – A colormap to use for generating colors. IfNone,mpl.rcParams["axes.prop_cycle"]is used.priors (
Mapping[Any,float] |None(default:None)) – A dictionary mapping values to their prior probabilities. Values with higher priors will be assigned less saturated colors.sort (
str|None(default:None)) – How to sort the categories. One ofNone,"alphabetical","frequency", or"random". IfNone, existing categories order is used or natural sorting.random_state (
int|None(default:None)) – Random seed for sampling. Only used ifsortis"random".
- Return type:
- Returns:
palette - Color palette for the given key
Examples
Get character color palette with saturation adjusted by indel probability:
>>> tdata = py.datasets.yang22() >>> indel_palette = py.get.palette( ... tdata, ... "characters", ... custom={"-": "white", "*": "lightgrey"}, ... cmap="gist_rainbow", ... priors=tdata.uns["priors"], ... sort="random", ... )