Hi, I am analyzing a single-cell dataset with Scanpy. Originally it was a Seurat Object and each cell had a label for the cluster it belonged to (30 clusters). I have transformed it to Anndata while preserving that classification for comparison in adata.obs[‘seurat_clusters’].
I have redone the analysis with Scanpy starting from raw counts, filtering, normalizing, scaling, PCA, neighborhood graph, Leiden clustering at varying resolutions and UMAP, and when I get to plot UMAP with sc.pl.umap(color=‘seurat_clusters’), the following is shown:
I want to plot the 30 clusters as categorical variables andcolor cells with a palette of 30 different colors, but I don’t know how to do that and why Scanpy thinks these clusters should be shown as continuous.
Thank you in advance"
The column probably has numeric values, so scanpy
treats them as continuous variables. Try setting the column as a categorical. Something like this:
import pandas as pd
adata.obs["seurat_clusters"] = pd.Categorical(adata.obs["seurat_clusters"])
Thank you so much, it worked!