Phone:+16179821253
Address: 315 W 3rd St, Boston, Massachusetts, 02127, USA
Email: sloanecarter773@gmail.com
Phone:+16179821253
Address: 315 W 3rd St, Boston, Massachusetts, 02127, USA
Email: sloanecarter773@gmail.com
How to draw and read gene expression violin plots in Seurat and Scanpy, including stacked violins and zero-heavy single-cell data.
In single-cell and bulk RNA-seq, a violin plot shows how a gene’s expression is spread across the cells or samples in each group, such as clusters or conditions. In R, Seurat’s VlnPlot() draws them. In Python, Scanpy’s sc.pl.violin() and sc.pl.stacked_violin() do the same job. The tricky part is reading them, because single-cell values are full of zeros and are usually log-normalised.
For a quick figure from an exported table of values, you can also paste the numbers into our free violin plot maker and download the chart.
A cluster of a few thousand cells rarely has a neat bell-shaped expression profile. Often a share of cells express a gene strongly and the rest show nothing. A bar chart of means hides that completely. A boxplot can collapse to a line at zero if more than half the cells are zero. A violin shows both parts: the bulge at zero and the shape of the expressing cells above it. For the general idea, see violin plot vs box plot.
VlnPlot() takes a Seurat object and one or more features. By default it groups cells by their current identity, which is usually the cluster labels.
library(Seurat)
# marker genes across clusters
VlnPlot(pbmc, features = c("MS4A1", "CD79A"))
# group by a metadata column instead, and hide the points
VlnPlot(pbmc, features = "CD3E", group.by = "orig.ident", pt.size = 0)
# compare conditions within each cluster
VlnPlot(pbmc, features = "IFIT1", split.by = "condition", pt.size = 0)
Arguments worth knowing:
features: genes, or anything FetchData() can return, such as QC metrics or PC scores.group.by: a metadata column to group by instead of the active identity.split.by: a second factor, such as condition, drawn within each group.pt.size: the size of the cell points. With thousands of cells, pt.size = 0 usually gives a cleaner plot.layer: which data layer to plot. In Seurat v5 this replaces the deprecated slot. The default is the normalised data. layer = "counts" plots raw counts.log: puts the expression axis on a log scale.stack and flip: draw many genes as one compact stacked figure (see below).add.noise: on by default. It adds a small amount of noise to the values for plotting. Set it to FALSE if you want the exact values drawn.Violins are also the standard QC view in Seurat workflows, showing genes per cell, counts per cell and mitochondrial percentage:
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
VlnPlot(pbmc, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
Because VlnPlot() returns a ggplot (or a patchwork of them), you can add ggplot2 layers and themes. To go further with ggplot2’s own geom_violin(), see our violin plot in R guide.
Scanpy works on an AnnData object. keys are gene names from adata.var_names or columns of adata.obs. groupby is a categorical column in adata.obs, such as cluster labels.
import scanpy as sc
adata = sc.datasets.pbmc68k_reduced() # small example dataset
# two genes across cell types, with jittered cells on top
sc.pl.violin(adata, keys=["CD79A", "NKG7"], groupby="bulk_labels",
jitter=0.4, stripplot=True, size=1, rotation=90)
# no points, which is faster for large datasets
sc.pl.violin(adata, keys="CST3", groupby="louvain", stripplot=False)
# QC metrics, each in its own panel
sc.pl.violin(adata, keys=["n_genes", "percent_mito"],
jitter=0.4, multi_panel=True)
stripplot (default True) overlays the individual cells. jitter spreads them sideways, and size sets the dot size.use_raw defaults to using adata.raw when it exists. layer picks a named layer and takes precedence over use_raw.density_norm sets how widths compare: "width" (the default here), "area" or "count". Older Scanpy code calls this scale.log=True uses a log axis, and order fixes the group order.Scanpy draws violins with seaborn, so extra keyword arguments pass through to seaborn.violinplot(). Our violin plot in Python guide covers those options.
One violin panel per gene gets unwieldy past a handful of markers. A stacked violin plot puts genes along one axis and groups along the other, with a small violin in each cell of the grid. It is a compact way to show a marker panel across clusters.
markers = ["CD79A", "MS4A1", "CD3D", "NKG7", "CST3", "LYZ", "FCGR3A"]
sc.pl.stacked_violin(adata, markers, groupby="bulk_labels")
# group the genes under labels
marker_groups = {"B": ["CD79A", "MS4A1"],
"T/NK": ["CD3D", "NKG7"],
"Myeloid": ["CST3", "LYZ"]}
sc.pl.stacked_violin(adata, marker_groups, groupby="bulk_labels")
By default each violin is coloured by the median expression in that group, which adds a heatmap-like cue. swap_axes=True flips the layout, and dendrogram=True orders the groups by similarity.
In Seurat, the equivalent is stack = TRUE:
markers <- c("CD79A", "MS4A1", "CD3D", "NKG7", "CST3", "LYZ")
VlnPlot(pbmc, features = markers, stack = TRUE, flip = TRUE) + NoLegend()
Most genes are detected in only some cells, partly because of real biology and partly because of how little RNA is captured per cell. On a violin, that shows up as a wide base sitting on zero. Some practical rules:
Smoothing matters a lot with spiky data like this. The violin plot bandwidth guide shows how the shape shifts as smoothing changes. For general reading tips, see how to read a violin plot.
In both standard workflows, the default values on the y axis are not raw counts.
NormalizeData() with the default LogNormalize method divides each cell’s counts by its total, multiplies by a scale factor of 10,000, and takes the natural log of the value plus one.sc.pp.normalize_total(adata, target_sum=1e4) followed by sc.pp.log1p(adata), which gives values on a similar scale.So a value of 2 is not “2 molecules”. It is the log of a depth-normalised count. Differences on this axis are roughly differences in log scale, which is why the shapes look less skewed than raw counts would. Label the axis to say so, for example “log-normalised expression”.
Be careful with scaled data. Seurat’s ScaleData() and Scanpy’s sc.pp.scale() centre each gene to a mean of zero. Violins of scaled values have negative values by design and no longer show the zero spike in the same way. They suit heatmaps more than violins. Also check whether Scanpy is plotting adata.raw or adata.X, since use_raw defaults to the raw slot when it exists.
A violin plot is a picture of the distribution, not a test. Treating each cell as an independent replicate when comparing conditions can overstate significance, because cells from the same sample are not independent. If you compare conditions, do it at the level of biological samples, for example with pseudobulk methods, and use violins to show the data rather than to prove a difference.
For background on the chart itself, read the violin plot guide. If you have a small table of expression values for a talk or report, you can make a violin plot online without loading the full dataset.
Many cells have no detected reads for that gene. The width at zero reflects the share of non-expressing cells, which is normal in single-cell data.
Set pt.size = 0. In Scanpy, set stripplot=False.
The normalised data layer, which after NormalizeData() is log-normalised expression. Use layer = "counts" for raw counts.
When you want to show many marker genes across many groups in one figure. Use sc.pl.stacked_violin() in Scanpy or VlnPlot(..., stack = TRUE) in Seurat.
Transform complex datasets into clear, interactive visualizations with Violin Plot. Start exploring data distributions in a way that empowers insight and drives smarter decisions.



