Skip to content
svgbrushablestrip

Strip plot with mean ± CI

What do all the observations look like per group, next to the group mean and its uncertainty?

Demo data · seed 20261101 · 100 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Look at the dots first: each one is an observation, spread sideways only so they don't overlap.
  2. Read the bar beside them: the group mean with its interval.
  3. Compare intervals with the spread of the dots: a narrow interval is about the mean, not about individual values.
  1. Callout 1: Each dot is one observation.
  2. Callout 2: The bar: mean and its interval.
  3. Callout 3: A wide spread in one group: does the mean describe it well?

Watch out

  • Check which interval is shown: a standard deviation, a standard error and a confidence interval have very different widths.

Defaults

Interval
95% CI (t)
What the interval shows: a confidence interval, a standard error or a standard deviation.
Also: ± 1 SE · ± 1 SD · None
Jitter width
0.5
How far points spread sideways, so they don't overlap; the spread has no meaning.
Range 0 to 1, step 0.1
Point radius
2.5
The size of each point.
Range 1 to 5, step 0.5

Pinned in the code

  • Interval: x̄ ± t(0.975, n−1)·s/√n (s with n − 1); SE = s/√n; SD = s. Say which one in captions — they are not interchangeable.
  • Jitter is deterministic (seeded per group) and only horizontal; values are never moved.
# Strip plot with mean ± CI — Codesplash Chart Lab (recipe "strip")
# controls: interval=ci, jitter=0.5, size=2.5
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("strip-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["fertilizer"] = pd.Categorical(df["fertilizer"].astype("string"), categories=["None", "Nitrogen", "Phosphate", "Both"])

def groups(frame, value, group=None, max_levels=12):
    """(label, values) per group in level order; rows missing the value or the group are dropped."""
    if group is None:
        return [(value, frame[value].dropna().to_numpy(dtype=float))]
    d = frame[[value, group]].dropna()
    out = []
    for level in list(d[group].cat.categories)[:max_levels]:
        v = d.loc[d[group] == level, value].to_numpy(dtype=float)
        if v.size:
            out.append((str(level), v))
    return out

parts = groups(df, "yield_t_ha", "fertilizer", max_levels=12)
rng = np.random.default_rng(23)  # horizontal jitter only (cosmetic); values are never moved
fig, ax = plt.subplots(figsize=(7, 4))
for i, (label, v) in enumerate(parts):
    ax.scatter(i + rng.uniform(-0.5 / 2, 0.5 / 2, v.size), v, s=(2 * 2.5) ** 2, color=PALETTE[i % len(PALETTE)], alpha=0.55, linewidths=0)
    n, m, s = v.size, v.mean(), v.std(ddof=1)
    if n > 1:
        half = stats.t.ppf(0.975, n - 1) * s / np.sqrt(n)  # 95% CI: t(0.975, n − 1) · s/√n
        ax.errorbar(i, m, yerr=half, fmt="o", color=plt.rcParams["text.color"], capsize=4, markersize=5, zorder=3)
ax.set_xticks(range(len(parts)), [label for label, _ in parts])
ax.set_xlabel("fertilizer")
ax.set_ylabel("yield_t_ha")
ax.set_title("mean ± 95% CI (t)", loc="left", fontsize=9)
plt.show()

Needs pandas, numpy, matplotlib, scipy · reads strip-demo.csv · app theme from the optional codesplash helper

  • Jitter comes from a seeded generator in each language, so dot positions differ from the app; values, means and intervals are identical.