Volcano plot
A volcano plot shows effect size (log2 fold change) on x and significance (−log10 p-value) on y for thousands of genes or proteins, so the strongest, most significant hits sit in the upper corners.
When to use it
- Differential expression or proteomics results with fold changes and p-values.
- You want to highlight hits passing both a fold-change and a significance cut-off.
Ask for it in pltchat
Upload your file and type something like:
"volcano plot, highlight genes with |log2FC| > 1 and padj < 0.05, label the top 5"
pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.
The matplotlib code
Self-contained with example data; swap in pd.read_csv(...) or
pd.read_excel(...) for your own file.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
rng = np.random.default_rng(21)
n = 3000
lfc = rng.normal(0, 0.8, n)
p = np.clip(10 ** -(np.abs(lfc) * rng.gamma(2, 1.2, n)), 1e-30, 1)
df = pd.DataFrame({"gene": [f"G{i}" for i in range(n)], "log2fc": lfc, "padj": p})
df["nlp"] = -np.log10(df["padj"])
sig = (df["padj"] < 0.05) & (df["log2fc"].abs() > 1)
fig, ax = plt.subplots(figsize=(6.4, 4))
ax.scatter(df.loc[~sig, "log2fc"], df.loc[~sig, "nlp"], s=5, color="lightgray")
up = sig & (df["log2fc"] > 0)
ax.scatter(df.loc[up, "log2fc"], df.loc[up, "nlp"], s=6, color="C3", label="Up")
ax.scatter(df.loc[sig & ~up, "log2fc"], df.loc[sig & ~up, "nlp"], s=6,
color="C0", label="Down")
for _, r in df[sig].nlargest(5, "nlp").iterrows():
ax.annotate(r["gene"], (r["log2fc"], r["nlp"]), fontsize=7,
xytext=(3, 3), textcoords="offset points")
ax.axhline(-np.log10(0.05), ls="--", lw=0.8, color="gray")
for x in (-1, 1):
ax.axvline(x, ls="--", lw=0.8, color="gray")
ax.set_xlabel("log2 fold change")
ax.set_ylabel("−log10 adjusted p")
ax.legend()
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.