Skip to content
svgcontrol-chart

Control chart

Is the process in statistical control, and where are the signals?

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

How to read it

  1. Read points in time order against the centre line.
  2. Points beyond the red limits, or runs on one side, signal a special cause.
  3. Read the spread chart first: its limits must be stable before the means chart can be trusted.
  1. Callout 1: Signals: points beyond the limits or breaking a rule.
  2. Callout 2: The centre line.
  3. Callout 3: The range chart: variability over time.

Watch out

  • Control limits describe the process, not the specification: a stable process can still make bad parts.

Defaults

Show ±1σ / ±2σ zones
Off
Shade the bands used by the zone rules.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Limits are drawn as sent, stepping between samples when they vary (p, u charts with varying n; Laney p′). Without a signal role, points beyond the limits are marked.
  • Zones divide the distance from the centre to each limit into thirds (Western Electric zones A, B, C); rule labels come from the engine (Nelson / Western Electric rule numbers).
# Control chart — Codesplash Chart Lab (recipe "control-chart")
# controls: zones=false
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"]

df = pd.read_csv("control-chart-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["chart"] = pd.Categorical(df["chart"].astype("string"), categories=["X̄", "R"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
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)))
I = "subgroup"
V = "statistic"
CL = "centre"
LCL = "lcl"
UCL = "ucl"
VIO = "signal"
RULE = "rule"
CHART = "chart"
charts = levels_of(df[CHART]) if CHART else [None]
fig, axes = plt.subplots(len(charts), 1, figsize=(8, 2.6 * len(charts)), sharex=True, squeeze=False)
for ax, ch in zip(axes[:, 0], charts):
    d = (df if ch is None else df[df[CHART].astype(str) == str(ch)]).sort_values(I)
    out = d[VIO].astype(bool) if VIO else (d[V] > d[UCL]) | (d[V] < d[LCL])
    ax.step(d[I], d[CL], where="mid", color="grey", linewidth=1)
    ax.step(d[I], d[UCL], where="mid", color=REF, linestyle="--", linewidth=1)
    ax.step(d[I], d[LCL], where="mid", color=REF, linestyle="--", linewidth=1)
    ax.plot(d[I], d[V], marker="o", ms=3.5, color=PALETTE[0], linewidth=1.2)
    ax.scatter(d.loc[out, I], d.loc[out, V], color="#ce5342", s=40, zorder=3)
    ax.set_ylabel(str(ch) if ch is not None else V)
axes[-1, 0].set_xlabel(I)
plt.show()

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