text: user9698: 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
  
  user3848: My recommendation is to report the issue directly on the ScanPy Github page here: https://github.com/scverse/scanpy/issues
  This is a shortcoming with the testing of the algorithm, without any question. Replicates with experimental modification are standard procedure in this line of analysis. For example, one in vitro cell culture does not receive the drug therapy, i.e. a control, and the rest do, which results in one group with a complete absence of a transcript profile. The authors simply have not described this possibility in any of their documentation and therefore may not have originally considered it.
  What I suspect has happened is the authorship only tested extensive and complete data - like really big data sets. "BigData" is what ScanPy is targeting because they look to have adapted to large data in Wolf et al Genome Biology 2018 paper, notably by specifying how quick their algorithm performs with increasing data set size.
  What I suspect has happened is that smaller data sets, with experimental replication and modification, were not tested so these issues simply get missed. It's easy to overlook, the authors can't think of everything.
  The authors of ScanPy are responding to issues arising unevenly. So it will be hit and miss whether they respond. Similar issues should have been reported to them before because its a common wet-lab experimental design. However, I've not checked their full intray.
  They should provide the bit of code that will prevent the tedium described above, but then again they may not. If they do, please do write back. The whole ScanPy project is interesting.
  
original_text: 9698: <p>Some of my samples have empty clusters. I want to keep the same color for each cluster in different plots.</p>
  <p>How do I get <code>sc.pl.umap</code> to keep the same colors for each cluster, even when a cluster is empty?</p>
  <pre><code>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('')
  
  </code></pre>
  <p><img src="https://user-images.githubusercontent.com/33963919/209980418-3ffb8db2-bcdc-4baf-8177-7c0d332394c6.png" alt="image" />
  Thanks</p>
   3848: <p>My recommendation is to report the issue directly on the <code>ScanPy</code> Github page here: <a href="https://github.com/scverse/scanpy/issues" rel="nofollow noreferrer">https://github.com/scverse/scanpy/issues</a></p>
  <p>This is a shortcoming with the testing of the algorithm, without any question. Replicates with experimental modification are standard procedure in this line of analysis. For example, one <em>in vitro</em> cell culture does not receive the drug therapy, i.e. a control, and the rest do, which results in one group with a complete absence of a transcript profile. The authors simply have not described this possibility in any of their documentation and therefore may not have originally considered it.</p>
  <p>What I suspect has happened is the authorship only tested extensive and complete data - like really big data sets. &quot;BigData&quot; is what <code>ScanPy</code> is targeting because they look to have adapted to large data in Wolf <em>et al</em> Genome Biology 2018 paper, notably by specifying how quick their algorithm performs with increasing data set size.</p>
  <p>What I suspect has happened is that smaller data sets, with experimental replication and modification, were not tested so these issues simply get missed. It's easy to overlook, the authors can't think of everything.</p>
  <p>The authors of <code>ScanPy</code> are responding to issues arising unevenly. So it will be hit and miss whether they respond. Similar issues should have been reported to them before because its a common wet-lab experimental design. However, I've not checked their full intray.</p>
  <p>They should provide the bit of code that will prevent the tedium described above, but then again they may not. If they do, please do write back. The whole <code>ScanPy</code> project is interesting.</p>
  