Custom Colors for UMAP

Hi Scanpy Discoursers,

I am trying to lineup my plots to have similar colors per phenotype and cluster.
Is there a straightforward way to control the color per cluster using the scanpy palettes?

Best,

Ed

Hi Edd,

All non float/int .obs features will be saved as categorical and have colors generated for them at the time of plotting. This color pallette will be used for all plots of the same feature. Colors can found in the .uns under ‘featurename_colors’ handle. If you would like to change them, you can replace hex’s in the order matching .obs feature category order. If you have not plotted your feature yet, you will have to convert it to pandas categorical, before adding colors to .uns.

See below for a simple example of changing colors for a feature.

Hope this helps,
Chuck

1 Like

Hi @herrinca,

Yes thank you! I solved this in a similar way.

colors_proto  = np.array(['#29397d', '#f7ff12', '#12ffef', '#0075fa'])
adata.uns['Disease.Etiology_colors'] = colors_proto

Best,

Ed

1 Like