scanpy.pl.StackedViolin#
- class scanpy.pl.StackedViolin(adata, var_names, groupby, *, use_raw=None, log=False, num_categories=7, categories_order=None, title=None, figsize=None, gene_symbols=None, var_group_positions=None, var_group_labels=None, var_group_rotation=None, layer=None, standard_scale=None, ax=None, vmin=None, vmax=None, vcenter=None, norm=None, **kwds)[source]#
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()
forAnnData
.- Parameters:
- adata
AnnData
Annotated data matrix.
- var_names
str
|Sequence
[str
] |Mapping
[str
,str
|Sequence
[str
]] var_names
should be a valid subset ofadata.var_names
. Ifvar_names
is a mapping, then the key is used as label to group the values (seevar_group_labels
). The mapping values should be sequences of validadata.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 mapping, then thevar_group_labels
andvar_group_positions
are set.- groupby
str
|Sequence
[str
] The key of the observation grouping to consider.
- use_raw
bool
|None
(default:None
) Use
raw
attribute ofadata
if present.- log
bool
(default:False
) Plot on logarithmic axis.
- num_categories
int
(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.
- categories_order
Sequence
[str
] |None
(default:None
) Order in which to show the categories. Note: add_dendrogram or add_totals can change the categories order.
- figsize
tuple
[float
,float
] |None
(default:None
) Figure size when
multi_panel=True
. Otherwise thercParam['figure.figsize]
value is used. Format is (width, height)- dendrogram
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
str
|None
(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
Sequence
[tuple
[int
,int
]] |None
(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 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 fourthvar_name
and the tenthvar_name
. By giving more positions, more brackets/color blocks are drawn.- var_group_labels
Sequence
[str
] |None
(default:None
) Labels for each of the
var_group_positions
that want to be highlighted.- var_group_rotation
float
|None
(default:None
) Label rotation degrees. By default, labels larger than 4 characters are rotated 90 degrees.
- layer
str
|None
(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, thenadata.X
is plotted. Iflayer
is set to a valid layer name, then the layer is plotted.layer
takes precedence overuse_raw
.- title
str
|None
(default:None
) Title for the figure
- stripplot
Add a stripplot on top of the violin plot. See
stripplot()
.- jitter
Add jitter to the stripplot (only when stripplot is True) See
stripplot()
.- size
Size of the jitter points.
- order
Order in which to show the categories. Note: if
dendrogram=True
the categories order will be given by the dendrogram andorder
will be ignored.- density_norm
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
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
Optional
[Literal
['var'
,'group'
]] (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
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- kwds
Are passed to
violinplot()
.
- adata
See also
stacked_violin()
simpler way to call StackedViolin but with less options.
violin()
to plot marker genes identified using
rank_genes_groups()
Examples
>>> import scanpy as sc >>> adata = sc.datasets.pbmc68k_reduced() >>> markers = ['C1QA', 'PSAP', 'CD79A', 'CD79B', 'CST3', 'LYZ'] >>> sc.pl.StackedViolin(adata, markers, groupby='bulk_labels', dendrogram=True) <scanpy.plotting._stacked_violin.StackedViolin object at 0x...>
Using var_names as dict:
>>> markers = {'T-cell': 'CD3D', 'B-cell': 'CD79A', 'myeloid': 'CST3'} >>> sc.pl.StackedViolin(adata, markers, groupby='bulk_labels', dendrogram=True) <scanpy.plotting._stacked_violin.StackedViolin object at 0x...>
Attributes
Methods
add_dendrogram
(*[, show, dendrogram_key, size])add_totals
(*[, show, sort, size, color])get_axes
()getdoc
()legend
(*[, show, title, width])Renders the image but does not call
matplotlib.pyplot.show()
.savefig
(filename[, bbox_inches])Save the current figure
show
([return_axes])Show the figure
style
(*[, cmap, stripplot, jitter, ...])swap_axes
(*[, swap_axes])Plots a transposed image.