Some of my samples have empty clusters. I want to keep the same color for each cluster in different plots.
How do I get sc.pl.umap
to keep the same colors for each cluster, even when a cluster is empty?
from matplotlib.pyplot import rc_context
with rc_context({'figure.figsize': (3, 3)}):
fig, (ax1, ax2) = plt.subplots(2, 2, figsize=(6,6))
ax1[0] = sc.pl.umap(adata[adata.obs['sample'] == adata.obs['sample'].cat.categories[0]],
color = 'leiden_r1', size=20,
legend_loc = 'on data', ax=ax1[0],
palette = mycolormap_26,
frameon=True, legend_fontsize = 8,title = adata.obs['sample'].cat.categories[0], show=False)
ax1[0].set_xlabel('')
ax1[0].set(xlim=xlim, ylim=ylim)
ax1[1] = sc.pl.umap(adata[adata.obs['sample'] == adata.obs['sample'].cat.categories[1]],
color = 'leiden_r1', size=20,
legend_loc = 'on data', ax=ax1[1],
palette = mycolormap_26,
frameon=True, legend_fontsize = 8,title = adata.obs['sample'].cat.categories[1], show=False)
ax1[1].set_xlabel('')
ax1[1].set_ylabel('')
ax1[1].set(xlim=xlim, ylim=ylim)
ax2[0] = sc.pl.umap(adata[adata.obs['sample'] == adata.obs['sample'].cat.categories[2]],
color = 'leiden_r1', size=20,
legend_loc = 'on data', ax=ax2[0],
palette = mycolormap_26,
frameon=True, legend_fontsize = 8,title = adata.obs['sample'].cat.categories[2], show=False)
ax2[0].set(xlim=xlim, ylim=ylim)
#ax2[0].set_xlabel('')
ax2[1] = sc.pl.umap(adata[adata.obs['sample'] == adata.obs['sample'].cat.categories[3]],
color = 'leiden_r1', size=20,
legend_loc = 'on data', ax=ax2[1],
palette = mycolormap_26,
frameon=True, legend_fontsize = 8,title = adata.obs['sample'].cat.categories[3], show=False)
ax2[1].set(xlim=xlim, ylim=ylim)
#ax2[1].set_xlabel('')
ax2[1].set_ylabel('')
Thanks
import scanpy as sc
. What about inserting a dumbie value, say single0,0
to prevent the skip? It appears UMAP1 cluster 1 is absent causing 2 and 3 ... thereon to change colour (colour) schemes for the proceeding colour (colour) $\endgroup$mycolormap_26
for each specific sample, which is tedious. $\endgroup$ScanPy
and could be reported (answer below). $\endgroup$