Error bar plot (mean ± SD, SEM or CI)
An error bar plot shows a point estimate (usually a mean) with a bar for its uncertainty. SD describes the spread of the data, SEM the precision of the mean, and a 95% CI the plausible range of the true mean.
When to use it
- You compare means across conditions or over time.
- You have replicate measurements at each point.
Watch out: Always say which error you plot. SEM bars look smaller than SD bars and are easy to misread.
Ask for it in pltchat
Upload your file and type something like:
"mean ± 95% CI of yield per fertilizer level, connect the points"
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(17)
levels = [0, 50, 100, 150, 200]
df = pd.DataFrame([{"level": l, "yield": 3 + 0.02 * l - 4e-5 * l**2 + rng.normal(0, 0.4)}
for l in levels for _ in range(8)])
s = df.groupby("level")["yield"].agg(["mean", "std", "count"])
ci = 1.96 * s["std"] / np.sqrt(s["count"])
fig, ax = plt.subplots(figsize=(6.4, 4))
ax.errorbar(s.index, s["mean"], yerr=ci, marker="o", capsize=4)
ax.set_xlabel("Fertilizer (kg N/ha)")
ax.set_ylabel("Yield (t/ha), mean ± 95% CI")
ax.spines[["top", "right"]].set_visible(False)
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.