Heatmap group color repeated for >20 groups


I am using sc.pl.heatmap and sc.pl.rank_genes_groups_heatmap to generate figures. However, the number of clusters in my data is more than 20. I think the number of predefined colors in the plotting function is limited to 20. So the last 4 (from the cluster 19 to 22) clusters have the same color. I was wondering if there is any way I can change the color or use different colormaps for the group bar.


I have figured it out. Pass a palette to sc.pl.umap, then plot the heatmap again will fix it. As mentioned in the link sc.pl.heatmap cannot show different colors for more than 20 cell types · Issue #548 · scverse/scanpy · GitHub.

Also, make sure the label you used in plotting umaps is ‘category’, otherwise it will not make any difference to your heatmap.