# How to get dot values from \`sc.pl.dotplot()\`?

**URL:** <https://discourse.scverse.org/t/how-to-get-dot-values-from-sc-pl-dotplot/2116>\
**Category:** scanpy\
**Created:** [February 23, 2024, 6:27pm UTC](https://discourse.scverse.org/t/how-to-get-dot-values-from-sc-pl-dotplot/2116 "2024-02-23T18:27:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdime](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/jdime/32/973_2.png) [@jdime](https://discourse.scverse.org/u/jdime)\
**Post date:** [February 23, 2024, 6:27pm UTC](https://discourse.scverse.org/t/how-to-get-dot-values-from-sc-pl-dotplot/2116/1 "2024-02-23T18:27:48Z")

</div>

Hello,  
I’m using the `sc.pl.dotplot` function to draw dotplots, and I’m interested to get the fraction of cells and mean expression values for each dot.  
If I assign the function call output to a variable dp, I can see some values related the axes, but is there a wat to get the values the dots?

I’m using this:

```auto
import scanpy as sc
adata = sc.datasets.pbmc68k_reduced()
markers = ['C1QA', 'PSAP', 'CD79A', 'CD79B', 'CST3', 'LYZ']
dp=sc.pl.dotplot(adata, markers, groupby="bulk_labels", return_fig=True)
dp
# <scanpy.plotting._dotplot.DotPlot at 0x7fd840a03df0>

dp.get_axes()
# {'mainplot_ax': <Axes: >,
# 'size_legend_ax': <Axes: title={'center': 'Fraction of cells\nin group (%)'}>,
# 'color_legend_ax': <Axes: title={'center': 'Mean expression\nin group'}>}

```

---

<div class="post-metadata">

**Author:** ![ivirshup](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/ivirshup/32/160_2.png) [@ivirshup](https://discourse.scverse.org/u/ivirshup)\
**Post date:** [March 1, 2024, 3:44pm UTC](https://discourse.scverse.org/t/how-to-get-dot-values-from-sc-pl-dotplot/2116/2 "2024-03-01T15:44:36Z")

</div>

There isn’t a direct way, but using the recent release candidate for `scanpy` you could use the new function `sc.get.aggregate` to accomplish this:

> **[scanpy.get.aggregate](https://scanpy.readthedocs.io/en/latest/generated/scanpy.get.aggregate.html)**

Something like:

```python
aggregated = sc.get.aggregate(
    adata[:, markers],
    by="bulk_labels",
    func=["sum", "count_nonzero"],
)
mean_in_expressed = aggregated.to_df(layer="sum") / aggregated.to_df(layer="count_nonzero")

```
