<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>

CC BY-SA 4.0
2023-01-02T14:23:18.287Z
2023-01-02T15:36:06.080Z
2023-01-02T15:36:06.080Z
M__
<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>

CC BY-SA 4.0
2022-12-29T22:27:52.620Z
Good question. I assume there's a `import scanpy as sc` . What about inserting a dumbie value, say single `0,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)
M__
CC BY-SA 4.0
2023-01-01T22:30:25.287Z
I can customize the color palette `mycolormap_26` for each specific sample, which is tedious.
Dan Li
CC BY-SA 4.0
2023-01-02T12:48:36.440Z
This could be scripted, which would remove the tedium, so it would only need to be done once. What you've hit is a shortcoming in `ScanPy` and could be reported (answer below).
M__
<single-cell>
How to preserve colour assignments in matplotlib when a category is empty?
# How to preserve colour assignments in matplotlib when a category is empty?

(Asked by: username_0 on 2022-12-29)

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

**Tags:** single-cell
> **Comments:**
> **username_1**: Good question. I assume there's a `import scanpy as sc` . What about inserting a dumbie value, say single `0,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)  
> **username_0**: I can customize the color palette `mycolormap_26` for each specific sample, which is tedious.  
> **username_1**: This could be scripted, which would remove the tedium, so it would only need to be done once. What you've hit is a shortcoming in `ScanPy` and could be reported (answer below).  

---

## 1 answers

### Answer by username_1 on 2023-01-02. Score: 1 | Accepted answer

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.


---

