Specifying color of UMAP cluster

Is there a way to specify the color of a UMAP cluster? I have two data sets so I have plotted a UMAP for each data set. I’m trying to compare the two, but I would like the clusters to be the same color (ex: the stem cells are shown in green in both UMAPs, the immune cells are shown in red in both UMAPs). I want to do this so that it’s easy to compare the two UMAPs.

Thanks!

Hi @ybarrer1,

You can pass a mapping of cluster to color via the palette parameter. For example:

import scanpy as sc

pbmc = sc.datasets.pbmc3k_processed()

# Subsetting to a smaller number of categories:
pbmc = pbmc[pbmc.obs["louvain"].isin(["CD4 T cells", "B cells", "CD8 T cells", "NK cells"])].copy()

sc.pl.umap(
    pbmc,
    color="louvain",
    palette={
        "CD4 T cells": "red",
        "CD8 T cells": "orange",
        "B cells": "green",
        "NK cells": "blue",
    }
)

image

You can pass anything matplotlib accepts as a color to specify colors. Internally, we represent it as a hex code.

Hi @ivirshup,

Thanks for your response. When I do this with my data, I get the following error:

Please check that the value of ‘palette’ is a valid matplotlib colormap string (eg. Set2), a list of color names or a cycler with a ‘color’ key.

Do you have any suggestions on how to move forward? I have previously tried the following code:
sc.pl.umap(adata_concat, color='leiden', legend_loc='on data', frameon=False, palette="Set2", color_map= mpl.cm .Reds)
Despite the same color palettes being used on my two UMAPs, the colors are still not synchronized.

Are you running the most recent version of scanpy?