scRNA-seq Dot Plot (Python)

Authors

[Editor] Shixiang Wang;

[Contributors] Claude Code โ€” AI-generated, independently AI-reviewed;

Modified

2026-10-19

๐Ÿค– AI Skill โ€” Download the Bizard unified skill for your AI assistant โฌ‡๏ธ Download Skill ZIP
๐Ÿ”Œ MCP Server โ€” Let AI agents (Claude Code, Cursor, โ€ฆ) query Bizard live: claude mcp add bizard -- npx @openbiox/bizard-mcp โ€” or the free hosted instance (no install, faster from mainland China): claude mcp add --transport http bizard http://biotree.top:38123/bizard-mcp/mcp ๐Ÿ“– MCP Docs
๐Ÿ“– Cite Bizard โ€” if Bizard helps your research, please cite: Li, K., Zheng, H., Huang, K., et al. (2026). Bizard: A Community-Driven Platform for Accelerating and Enhancing Biomedical Data Visualization. iMetaMed, e70038. ๐Ÿ”— DOI / BibTeX

The single-cell dot plot summarizes marker expression across clusters in one dense panel: dot size encodes the fraction of cells expressing the gene, dot colour the mean expression level. It is the standard โ€œwhich markers define which clusterโ€ summary in scRNA-seq papers. scanpy.pl.dotplot computes both encodings from the raw object.

Example

Setup

  • System Requirements: Cross-platform (Linux/MacOS/Windows)
  • Programming Language: Python
  • Dependencies: scanpy, anndata, pandas, numpy, matplotlib
import matplotlib.pyplot as plt
import scanpy as sc
import pandas as pd
import numpy as np

sc.settings.verbosity = 0
sc.settings.set_figure_params(dpi=90, facecolor='white')

Data Preparation

We reuse the simulated three-population PBMC dataset and identify each clusterโ€™s top markers with rank_genes_groups, then keep a curated set spanning all populations.

np.random.seed(241)

n_per = 400
genes = [f'Gene{i:02d}' for i in range(1, 31)]
blocks = {'T cells': (0, 10), 'B cells': (10, 20), 'Monocytes': (20, 30)}
counts = np.zeros((n_per * 3, 30))
labels = []
for i, (cell_type, (lo, hi)) in enumerate(blocks.items()):
    sl = slice(i * n_per, (i + 1) * n_per)
    counts[sl] = np.random.negative_binomial(4, 0.3, (n_per, 30))
    counts[sl, lo:hi] += np.random.negative_binomial(8, 0.2, (n_per, hi - lo))
    labels += [cell_type] * n_per

adata = sc.AnnData(counts.astype(np.float32))
adata.var_names = genes
adata.obs['CellType'] = pd.Categorical(labels, categories=blocks)

sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
sc.tl.rank_genes_groups(adata, 'CellType')
marker_genes = ['Gene01', 'Gene05', 'Gene09',
                'Gene12', 'Gene16', 'Gene19',
                'Gene22', 'Gene26', 'Gene30']

Visualization

Dot Plot of Curated Markers

var_names fixes the gene order, dendrogram=False keeps the biological grouping explicit, and the size legend explains the fraction encoding.

fig, ax = plt.subplots(figsize=(6.4, 3.6))
sc.pl.dotplot(adata, var_names=marker_genes, groupby='CellType',
              ax=ax, show=False, cmap='Reds',
              size_title='Fraction of cells', colorbar_title='Mean expression')
plt.tight_layout()
plt.show()
Figureย 1: Marker expression across populations: size = fraction expressing, colour = mean level

Ranked Markers per Cluster

Instead of a hand-curated list, feed each clusterโ€™s top-3 ranked genes โ€” the quick-look version right after rank_genes_groups.

rg = sc.get.rank_genes_groups_df(adata, group=None)
ranked = sorted(set(rg.names.head(9)))
fig, ax = plt.subplots(figsize=(6.4, 3.2))
sc.pl.dotplot(adata, var_names=ranked, groupby='CellType',
              ax=ax, show=False, cmap='Reds',
              size_title='Fraction of cells', colorbar_title='Mean expression')
plt.tight_layout()
plt.show()
Figureย 2: Top-3 ranked markers per population

References

  1. Wolf, F. A., Angerer, P., & Theis, F. J. (2018). SCANPY: large-scale single-cell gene expression data analysis. Genome Biology, 19, 15.
  2. Trapnell, C. (2015). Defining cell types and states with single-cell genomics. Genome Research, 25(10), 1491-1498.