episcanpy.pl.stacked_violin

episcanpy.pl.stacked_violin(adata, var_names, groupby=None, log=False, use_raw=None, num_categories=7, figsize=None, dendrogram=False, gene_symbols=None, var_group_positions=None, var_group_labels=None, standard_scale=None, var_group_rotation=None, layer=None, stripplot=False, jitter=False, size=1, scale='width', order=None, swap_axes=False, show=None, save=None, row_palette='muted', **kwds)

Stacked violin plots.

Makes a compact image composed of individual violin plots (from violinplot()) stacked on top of each other. Useful to visualize gene expression per cluster.

Wraps seaborn.violinplot() for AnnData.

Parameters
adata : AnnDataAnnData

Annotated data matrix.

var_names : str, Sequence[str], MappingUnion[str, Sequence[str], Mapping[str, Union[str, Sequence[str]]]]

var_names should be a valid subset of adata.var_names. If var_names is a mapping, then the key is used as label to group the values (see var_group_labels). The mapping values should be sequences of valid adata.var_names. In this case either coloring or ‘brackets’ are used for the grouping of var names depending on the plot. When var_names is a mapping, then the var_group_labels and var_group_positions are set.

groupby : str, NoneOptional[str] (default: None)

The key of the observation grouping to consider.

use_raw : bool, NoneOptional[bool] (default: None)

Use raw attribute of adata if present.

log : boolbool (default: False)

Plot on logarithmic axis.

num_categories : intint (default: 7)

Only used if groupby observation is not categorical. This value determines the number of groups into which the groupby observation should be subdivided.

figsize : Tuple[float, float], NoneOptional[Tuple[float, float]] (default: None)

Figure size when multi_panel=True. Otherwise the rcParam[‘figure.figsize] value is used. Format is (width, height)

dendrogram : bool, strUnion[bool, str] (default: False)

If True or a valid dendrogram key, a dendrogram based on the hierarchical clustering between the groupby categories is added. The dendrogram information is computed using scanpy.tl.dendrogram(). If tl.dendrogram has not been called previously the function is called with default parameters.

gene_symbols : str, NoneOptional[str] (default: None)

Column name in .var DataFrame that stores gene symbols. By default var_names refer to the index column of the .var DataFrame. Setting this option allows alternative names to be used.

var_group_positions : Sequence[Tuple[int, int]], NoneOptional[Sequence[Tuple[int, int]]] (default: None)

Use this parameter to highlight groups of var_names. This will draw a ‘bracket’ or a color block between the given start and end positions. If the parameter var_group_labels is set, the corresponding labels are added on top/left. E.g. var_group_positions=[(4,10)] will add a bracket between the fourth var_name and the tenth var_name. By giving more positions, more brackets/color blocks are drawn.

var_group_labels : Sequence[str], NoneOptional[Sequence[str]] (default: None)

Labels for each of the var_group_positions that want to be highlighted.

var_group_rotation : float, NoneOptional[float] (default: None)

Label rotation degrees. By default, labels larger than 4 characters are rotated 90 degrees.

layer : str, NoneOptional[str] (default: None)

Name of the AnnData object layer that wants to be plotted. By default adata.raw.X is plotted. If use_raw=False is set, then adata.X is plotted. If layer is set to a valid layer name, then the layer is plotted. layer takes precedence over use_raw.

stripplot : boolbool (default: False)

Add a stripplot on top of the violin plot. See stripplot().

jitter : float, boolUnion[float, bool] (default: False)

Add jitter to the stripplot (only when stripplot is True) See stripplot().

size : intint (default: 1)

Size of the jitter points.

order : Sequence[str], NoneOptional[Sequence[str]] (default: None)

Order in which to show the categories. Note: if dendrogram=True the categories order will be given by the dendrogram and order will be ignored.

scale : Literal_[area, count, width]Literal_[area, count, width] (default: 'width')

The method used to scale the width of each violin. If ‘width’ (the default), each violin will have the same width. If ‘area’, each violin will have the same area. If ‘count’, a violin’s width corresponds to the number of observations.

row_palette : strstr (default: 'muted')

The row palette determines the colors to use for the stacked violins. The value should be a valid seaborn or matplotlib palette name (see color_palette()). Alternatively, a single color name or hex value can be passed, e.g. ‘red’ or ‘#cc33ff’.

standard_scale : Literal_[var, obs], NoneOptional[Literal_[var, obs]] (default: None)

Whether or not to standardize a dimension between 0 and 1, meaning for each variable or observation, subtract the minimum and divide each by its maximum.

swap_axes : boolbool (default: False)

By default, the x axis contains var_names (e.g. genes) and the y axis the groupby categories. By setting swap_axes then x are the groupby categories and y the var_names. When swapping axes var_group_positions are no longer used

show : bool, NoneOptional[bool] (default: None)

Show the plot, do not return axis.

save : bool, str, NoneUnion[bool, str, None] (default: None)

If True or a str, save the figure. A string is appended to the default filename. Infer the filetype if ending on {‘.pdf’, ‘.png’, ‘.svg’}.

ax

A matplotlib axes object. Only works if plotting a single component.

**kwds

Are passed to violinplot().

Returns

List of Axes

Examples

>>> import scanpy as sc
>>> adata = sc.datasets.pbmc68k_reduced()
>>> markers = ['C1QA', 'PSAP', 'CD79A', 'CD79B', 'CST3', 'LYZ']
>>> sc.pl.stacked_violin(adata, markers, groupby='bulk_labels', dendrogram=True)

Using var_names as dict:

>>> markers = {'T-cell': 'CD3D', 'B-cell': 'CD79A', 'myeloid': 'CST3'}
>>> sc.pl.stacked_violin(adata, markers, groupby='bulk_labels', dendrogram=True)

See also

rank_genes_groups_stacked_violin()

to plot marker genes identified using the rank_genes_groups() function.