Line chart with a confidence band
A shaded band around a line shows uncertainty continuously, which reads better than error bars when there are many x values, as in time courses or model predictions.
When to use it
- Many x values, each with a mean and an uncertainty.
- Forecasts, model fits or averaged time courses.
Ask for it in pltchat
Upload your file and type something like:
"mean signal over time per condition with a shaded ± SD band"
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 matplotlib.pyplot as plt
rng = np.random.default_rng(18)
t = np.linspace(0, 10, 100)
fig, ax = plt.subplots(figsize=(6.4, 4))
for label, k in [("Control", 0.3), ("Treated", 0.6)]:
reps = 1 - np.exp(-k * t) + rng.normal(0, 0.06, (12, t.size))
mean, sd = reps.mean(0), reps.std(0)
ax.plot(t, mean, label=label)
ax.fill_between(t, mean - sd, mean + sd, alpha=0.25)
ax.set_xlabel("Time (min)")
ax.set_ylabel("Normalised signal")
ax.legend()
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.