Plot guides › Chart types

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.

Example error bar plot (mean ± sd, sem or ci) made with matplotlib
Rendered from the code below, with example data.

When to use it

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()

Make this with your data

Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.

Related plots