StackedViolin.add_totals(show=True, sort=None, size=0.8, color=None)[source]#

Show barplot for the number of cells in in groupby category.

The barplot is by default shown on the right side of the plot or on top if the axes are swapped.

show bool | None (default: True)

Boolean to turn on (True) or off (False) ‘add_totals’

sort Literal['ascending', 'descending'] (default: None)

Set to either ‘ascending’ or ‘descending’ to reorder the categories by cell number

size float | None (default: 0.8)

size of the barplot. Corresponds to width when shown on the right of the plot, or height when shown on top. The unit is the same as in matplotlib (inches).

color Union[str, tuple[float, ...], Sequence[Union[str, tuple[float, ...]]], None] (default: None)

Color for the bar plots or list of colors for each of the bar plots. By default, each bar plot uses the colors assigned in adata.uns[{groupby}_colors].

Return type:



Returns self for method chaining.


>>> import scanpy as sc
>>> adata = sc.datasets.pbmc68k_reduced()
>>> markers = {'T-cell': 'CD3D', 'B-cell': 'CD79A', 'myeloid': 'CST3'}
>>> plot =, markers, groupby='bulk_labels').add_totals()
>>> plot.plot_group_extra['counts_df']  
CD4+/CD25 T Reg                  68
CD4+/CD45RA+/CD25- Naive T        8
CD4+/CD45RO+ Memory              19
CD8+ Cytotoxic T                 54
CD8+/CD45RA+ Naive Cytotoxic     43
CD14+ Monocyte                  129
CD19+ B                          95
CD34+                            13
CD56+ NK                         31
Dendritic                       240
Name: count, dtype: int64