scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.89k stars 594 forks source link

An advice for color palette in adata.uns #2632

Open CocoGzh opened 1 year ago

CocoGzh commented 1 year ago

What kind of feature would you like to request?

Additional function parameters / changed functionality / changed defaults?

Please describe your wishes

As we all know, the color palette is a list stored in uns[f'{values_key}_colors']. I wonder if the color palette can be set to dictionary by default. This makes it easy to unify colors across different adata objects.

grst commented 1 year ago

Some official tooling in scanpy/anndata for this would be nice, but for now you can do

column = "<your anndata.obs column>"
colors = {"category1": "#123456"} # your color dict

adata.uns[f"{column}_colors"] = [
    colors[cat] for cat in adata.obs[column].cat.categories
]