# Plotting scanpy.tl.score\_genes() value using scanpy.pl.stacked\_violin()

**URL:** <https://discourse.scverse.org/t/plotting-scanpy-tl-score-genes-value-using-scanpy-pl-stacked-violin/897>\
**Category:** scanpy\
**Tags:** scrna-seq\
**Created:** [November 4, 2022, 12:28am UTC](https://discourse.scverse.org/t/plotting-scanpy-tl-score-genes-value-using-scanpy-pl-stacked-violin/897 "2022-11-04T00:28:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanb80](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/seanb80/32/431_2.png) [@seanb80](https://discourse.scverse.org/u/seanb80)\
**Post date:** [November 4, 2022, 12:28am UTC](https://discourse.scverse.org/t/plotting-scanpy-tl-score-genes-value-using-scanpy-pl-stacked-violin/897/1 "2022-11-04T00:28:04Z")

</div>

Hi,

I’m interested in using scanpy.pl.stacked\_violin() to plot multiple gene scores sc.tl.score\_genes(). As far as I can tell scanpy.pl.stacked\_violin() only takes var inputs and groups by an obs. Is there a way to do obs x obs with stacked\_violin or is there some technical reason I would not want to do this?

Thanks!

---

<div class="post-metadata">

**Author:** ![PauBadiaM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/paubadiam/32/410_2.png) [@PauBadiaM](https://discourse.scverse.org/u/PauBadiaM)\
**Post date:** [November 4, 2022, 8:53am UTC](https://discourse.scverse.org/t/plotting-scanpy-tl-score-genes-value-using-scanpy-pl-stacked-violin/897/2 "2022-11-04T08:53:39Z")

</div>

Hi @seanb80

As you mentioned, the way `sc.pl.stacked_violin` works is to check for `var_names` so you cannot use values stored in `obs`. One way to overcome this would be to create a new `AnnData` object where in `.X` you would store the obtained scores (extracted from `.obs` of the original `adata` object), with dimensions `n_cells x n_genesets`. This way you can plug this directly into `scanpy` plotting functions.

Just as an alternative example, this is how its done in `decoupler`:

```auto
import scanpy as sc
import pandas as pd
import decoupler as dc

# Load data
adata = sc.datasets.pbmc3k_processed()

# Define genesets
net = pd.DataFrame([
    ['gset B cells', 'CD74'],
    ['gset B cells', 'HLA-DRA'],
    ['gset B cells', 'HLA-DPB1'],
    ['gset T cells', 'CD3D'],
    ['gset T cells', 'CD3E'],
    ['gset T cells', 'IL32'],
    ], columns=['source', 'target']
)

# Run enrichment (equivalent of sc.tl.score_genes)
dc.run_ulm(adata, net, weight=None, min_n=0)

# Create new AnnData with geneset scores in .X
acts = dc.get_acts(adata, 'ulm_estimate')

# Plot UMAP scores
sc.pl.umap(acts, color=acts.var_names)

# Plot violin
sc.pl.stacked_violin(acts, var_names=acts.var_names, groupby='louvain', standard_scale='var')

```

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/1X/3326edbe05e73f8f5a8023659b8b0ac6bcaa35d4.png)

![image](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/1X/e21eea1dc110a86d9f8efbc64a6bcf4b99ea2c01.png)

More information here if interested: [Functional enrichment of biological terms — decoupler 1.2.1 documentation](https://decoupler-py.readthedocs.io/en/latest/notebooks/msigdb.html)
