scanpy.pl.stacked_violin¶
-
scanpy.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
seaborn.violinplot
) stacked on top of each other. Useful to visualize gene expression per cluster.Wraps
seaborn.violinplot
forAnnData
.See also
rank_genes_groups_stacked_violin()
to plot marker genes identified using therank_genes_groups()
function.- Parameters
- adata :
AnnData
Annotated data matrix.
- var_names :
str
, list ofstr
, dict or OrderedDict var_names
should be a valid subset ofadata.var_names
. Ifvar_names
is a dict, then the key is used as label to group the values (see var_group_labels). The dict values should be a list or str of valid adata.var_names. In this case either coloring or ‘brackets’ are used for the grouping of var names depending on the plot. Whenvar_names
is a dict, then thevar_group_labels
andvar_group_positions
are set.- groupby :
str
orNone
, optional (default:None
) The key of the observation grouping to consider.
- log :
bool
, optional (default:False
) Plot on logarithmic axis.
- use_raw :
bool
, optional (default:None
) Use
raw
attribute ofadata
if present.- num_categories :
int
, optional (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 : (
float
,float
), optional (default:None
) Figure size when multi_panel = True. Otherwise the rcParam[‘figure.figsize] value is used. Format is (width, height)
- dendrogram :
bool
orstr
, optional (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 usingscanpy.tl.dendrogram()
. Iftl.dendrogram
has not been called previously the function is called with default parameters.- gene_symbols : string, optional (default:
None
) Column name in
.var
DataFrame that stores gene symbols. By defaultvar_names
refer to the index column of the.var
DataFrame. Setting this option allows alternative names to be used.- var_group_positions : list of
tuples
. 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 parametervar_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 : list of
str
Labels for each of the var_group_positions that want to be highlighted.
- var_group_rotation :
float
(default:None
) Label rotation degrees. By default, labels larger than 4 characters are rotated 90 degrees
- layer :
str
, (defaultNone
) Name of the AnnData object layer that wants to be plotted. By default adata.raw.X is plotted. If
use_raw=False
is set, thenadata.X
is plotted. Iflayer
is set to a valid layer name, then the layer is plotted.layer
takes precedence overuse_raw
.- stripplot :
bool
optional (default:True
) Add a stripplot on top of the violin plot. See
seaborn.stripplot
.- jitter :
float
orbool
, optional (default:True
) Add jitter to the stripplot (only when stripplot is True) See
seaborn.stripplot
.- size : int, optional (default: 1)
Size of the jitter points.
- order : list of str, optional (default:
True
) Order in which to show the categories.
- scale : {'area', 'count', 'width'}, optional (default: 'width')
The method used to scale the width of each violin. If ‘area’, each violin will have the same area. If ‘count’, the width of the violins will be scaled by the number of observations in that bin. If ‘width’, each violin will have the same width.
- row_palette :
str
(default:muted
) The row palette determines the colors to use in each of the stacked violin plots. The value should be a valid seaborn palette name or a valic matplotlib colormap (see https://seaborn.pydata.org/generated/seaborn.color_palette.html). Alternatively, a single color name or hex value can be passed. E.g. ‘red’ or ‘#cc33ff’
- standard_scale : {'var', 'obs'}, optional (default: None)
Whether or not to standardize that dimension between 0 and 1, meaning for each variable or observation, subtract the minimum and divide each by its maximum.
- swap_axes :
bool
, optional (default:False
) By default, the x axis contains
var_names
(e.g. genes) and the y axis thegroupby
categories. By settingswap_axes
then x are thegroupby
categories and y thevar_names
. When swapping axes var_group_positions are no longer used- show
Show the plot, do not return axis.
- save
If
True
or astr
, 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 : keyword arguments
Are passed to
seaborn.violinplot
.
- adata :
- Returns
List of
Axes
Examples
>>> adata = sc.datasets.pbmc68k_reduced() >>> sc.pl.stacked_violin(adata, ['C1QA', 'PSAP', 'CD79A', 'CD79B', 'CST3', 'LYZ'], ... 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)