Enrichment 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

Enrichment results (GO/KEGG/reactome) are read through two standard displays: a ranked bar chart of โˆ’log10 adjusted p-values, and a dot plot that additionally encodes the gene ratio by dot size. Both are plain matplotlib/seaborn layers over the result table โ€” the same recipe works on any toolโ€™s output (gseapy, clusterProfiler exports, ReactomePA).

Example

Setup

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

Data Preparation

We simulate a ten-term enrichment table: pathway names, gene counts, ratios and adjusted p-values, ordered by significance โ€” the columns every enrichment tool exports.

enrich = pd.DataFrame({
    'Pathway': ['T cell activation', 'Antigen processing', 'IFN-gamma response',
                'IL-6/JAK/STAT3', 'TNF-alpha signaling', 'Leukocyte migration',
                'Complement cascade', 'Oxidative phosphorylation',
                'Fatty acid metabolism', 'DNA repair'],
    'Count': [42, 35, 28, 24, 22, 19, 17, 12, 9, 6],
    'GeneRatio': [0.28, 0.24, 0.21, 0.18, 0.17, 0.14, 0.12, 0.09, 0.07, 0.05],
    'padj': [1e-9, 4e-8, 2e-6, 8e-5, 3e-4, 2e-3, 9e-3, 0.04, 0.12, 0.31],
})
enrich['NegLogP'] = -np.log10(enrich.padj)

Visualization

Ranked Bar Chart

Horizontal bars sorted by โˆ’log10 padj with a significance threshold line; value labels make the figure self-contained.

top = enrich.sort_values('NegLogP')

fig, ax = plt.subplots(figsize=(6.8, 4.4))
ax.barh(top.Pathway, top.NegLogP, color='#8da0cb',
        edgecolor='0.25', linewidth=0.6)
for y, v in enumerate(top.NegLogP):
    ax.text(v + 0.06, y, f'{v:.1f}', va='center', fontsize=8.5, color='0.25')
ax.axvline(-np.log10(0.05), color='#e63946', linewidth=0.9, linestyle='--')
ax.text(-np.log10(0.05) + 0.06, -0.55, 'padj = 0.05', fontsize=8.5,
        color='#e63946')
ax.set_xlabel('-log$_{10}$ (adjusted p-value)')
ax.spines[['top', 'right']].set_visible(False)
plt.tight_layout()
plt.show()
Figureย 1: Enriched pathways ranked by -log10 adjusted p-value

Dot Plot with Gene Ratio

The dot plot adds a third variable: dot size for the gene count, colour for the ratio โ€” the format popularized by clusterProfiler.

top = enrich.sort_values('NegLogP')

fig, ax = plt.subplots(figsize=(6.8, 4.6))
sc = ax.scatter(top.NegLogP, top.Pathway, s=top.Count * 9,
                c=top.GeneRatio, cmap='YlGnBu', edgecolor='0.3',
                linewidth=0.7, vmin=0, vmax=top.GeneRatio.max())
cb = fig.colorbar(sc, ax=ax, shrink=0.7)
cb.set_label('Gene ratio')
ax.axvline(-np.log10(0.05), color='#e63946', linewidth=0.9, linestyle='--')
ax.set_xlabel('-log$_{10}$ (adjusted p-value)')
ax.spines[['top', 'right']].set_visible(False)
plt.tight_layout()
plt.show()
Figureย 2: Enrichment dot plot: ratio by colour, count by size

References

  1. Yu, G., Wang, L. G., Han, Y., & He, Q. Y. (2012). clusterProfiler: an R package for comparing biological themes among gene clusters. OMICS, 16(5), 284-287.
  2. Hunter, J. D. (2007). Matplotlib: A 2D graphics environment. Computing in Science & Engineering, 9(3), 90-95.