Skip to content
svgprofile-plot

Profile plot

Do the groups' mean profiles run parallel across the measures, at the same level, and is the common profile flat?

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

How to read it

  1. Read each line as a group's means across measures.
  2. Parallel lines: the same shape, possibly at different levels.
  3. Non-parallel lines: the groups change differently.
  1. Callout 1: Lines run roughly parallel here.
  2. Callout 2: The vertical gap: the level difference.
  3. Callout 3: Measures need a common scale.

Watch out

  • Measures on different scales make the shapes meaningless.

Defaults

Show intervals
On
Add confidence intervals at each point.

Pinned in the code

  • Draws the engine's group means as given, in the measures' order; intervals are each mean's own t interval (not simultaneous, and not the test).
  • Groups are dodged slightly so overlapping intervals stay visible; lines connect consecutive measures only.
  • Profile analysis tests parallelism (equal successive differences), levels (equal group averages) and flatness (equal measure averages) — the plot shows all three at once.
# Profile plot — Codesplash Chart Lab (recipe "profile-plot")
# controls: intervals=true
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

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"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["-", (0, (6, 3)), (0, (1.5, 2.5)), (0, (8, 3, 2, 3)), (0, (12, 4)), (0, (3, 3)), (0, (8, 2, 2, 2, 2, 2)), (0, (1.5, 5))]
SERIES_MARKERS = ["o", "s", "^", "D", "P", "*", "2", "v"]

df = pd.read_csv("profile-plot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["measure"] = pd.Categorical(df["measure"].astype("string"), categories=["hour 1", "hour 2", "hour 3", "hour 4", "hour 5"])
df["treatment"] = pd.Categorical(df["treatment"].astype("string"), categories=["control", "A", "B"])

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
M = "measure"
V = "mean score"
G = "treatment"
LO = "CI low"
HI = "CI high"
measures = levels_of(df[M])
pos = {m: i for i, m in enumerate(measures)}
fig, ax = plt.subplots(figsize=(7, 4.5))
ks = levels_of(df[G]) if G else ["all"]
many = len(ks) > 1  # several groups: dash and marker shape per profile, as in the app
for i, k in enumerate(ks):
    g = (df[df[G].astype(str) == str(k)] if G else df).copy()
    g["_x"] = g[M].astype(str).map(pos)
    g, col = g.sort_values("_x"), PALETTE[i % len(PALETTE)]
    ax.plot(g["_x"], g[V], marker=SERIES_MARKERS[i % 8] if many else "o", linestyle=SERIES_DASHES[i % 8] if many else "-", color=col, label=str(k))
    if LO and HI:
        ax.vlines(g["_x"], g[LO], g[HI], color=col, alpha=0.6)
ax.set_xticks(range(len(measures)), measures)
ax.set_xlabel(M)
ax.set_ylabel(V)
if G:
    ax.legend(title=G, fontsize=8)
plt.show()

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