svgcapability-histogram
Process capability
Does the process fit inside its specification limits, and how much falls outside?
How to read it
- Read the histogram and curve as the process output.
- Compare with the red specification limits.
- Read the indices at the top: how comfortably the process fits.
- Callout 1: The lower specification limit.
- Callout 2: The upper specification limit.
- Callout 3: A process centred away from the target.
- Callout 4: Pp, Ppk and the share outside.
Watch out
- Capability assumes a stable process and a suitable distribution. Check the control chart first.
Defaults
- Lower specification limit (null = none)
- 9.95
- The smallest value the requirement accepts.
- Range -1,000,000,000 to 1,000,000,000, step 0.001
- Upper specification limit (null = none)
- 10.05
- The largest value the requirement accepts.
- Range -1,000,000,000 to 1,000,000,000, step 0.001
- Target (null = none)
- 10
- The outcome you want to reach; the chart shows the chance of missing it.
- Range -1,000,000,000 to 1,000,000,000, step 0.001
Pinned in the code
- Bins: equal width over the values and limits (at least 10, Sturges otherwise). The fitted curve is the engine's (normal or a Box–Cox/Johnson fit, as sent); without one, a normal density with the sample mean and SD.
- Pp/Ppk in the legend use the overall (long-term) SD of the plotted values; Cp/Cpk from within-subgroup variation come from the engine's capability table.
- Specification limits are customer requirements, not control limits; send null for a one-sided specification.
# Process capability — Codesplash Chart Lab (recipe "capability-histogram")
# controls: lsl=9.95, usl=10.05, target=10
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("capability-histogram-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
V = "diameter (mm)"
FX = None
FD = None
LSL, USL, TARGET = 9.95, 10.05, 10
v = df[V].dropna()
lims = [x for x in (LSL, USL) if x is not None]
edges = np.linspace(min([v.min()] + lims), max([v.max()] + lims), max(10, int(np.ceil(np.log2(len(v)) + 1))) + 1)
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.hist(v, bins=edges, density=True, color=PALETTE[0], alpha=0.45, edgecolor="white")
if FX and FD:
f = df.dropna(subset=[FX, FD]).sort_values(FX)
ax.plot(f[FX], f[FD], color=PALETTE[0], linewidth=2)
else: # normal with the sample mean and SD (overall)
xs = np.linspace(edges[0], edges[-1], 200)
ax.plot(xs, stats.norm.pdf(xs, v.mean(), v.std(ddof=1)), color=PALETTE[0], linewidth=2)
for x, name, col, ls in ((LSL, "LSL", "#ce5342", "--"), (USL, "USL", "#ce5342", "--"), (TARGET, "target", "#19966e", ":")):
if x is not None:
ax.axvline(x, color=col, linestyle=ls, linewidth=1.4)
ax.annotate(name, (x, 1), xycoords=("data", "axes fraction"), ha="center", va="bottom", fontsize=8, color=col)
s = v.std(ddof=1)
if LSL is not None and USL is not None:
ax.set_title(f"Pp {(USL - LSL) / (6 * s):.3f} · Ppk {min((USL - v.mean()) / (3 * s), (v.mean() - LSL) / (3 * s)):.3f}", fontsize=9, loc="left")
ax.set_xlabel(V)
ax.set_ylabel("density")
plt.show()Needs pandas, numpy, matplotlib, scipy · reads capability-histogram-demo.csv · app theme from the optional codesplash helper
# Process capability — Codesplash Chart Lab (recipe "capability-histogram")
# controls: lsl=9.95, usl=10.05, target=10
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
df = pd.read_csv("capability-histogram-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
V = "diameter (mm)"
FX = None
FD = None
LSL, USL, TARGET = 9.95, 10.05, 10
v = df[V].dropna()
lims = [x for x in (LSL, USL) if x is not None]
edges = np.linspace(min([v.min()] + lims), max([v.max()] + lims), max(10, int(np.ceil(np.log2(len(v)) + 1))) + 1)
dens, _ = np.histogram(v, bins=edges, density=True)
fig = go.Figure(go.Bar(x=(edges[:-1] + edges[1:]) / 2, y=dens, width=np.diff(edges), marker_color=PALETTE[0], opacity=0.5, name=V))
xs = np.linspace(edges[0], edges[-1], 200)
fit = (df.dropna(subset=[FX, FD]).sort_values(FX)[FX], df.dropna(subset=[FX, FD]).sort_values(FX)[FD]) if FX and FD else (xs, stats.norm.pdf(xs, v.mean(), v.std(ddof=1)))
fig.add_scatter(x=fit[0], y=fit[1], mode="lines", line=dict(color=PALETTE[0], width=2), name="fit")
for x, name, col in ((LSL, "LSL", "#ce5342"), (USL, "USL", "#ce5342"), (TARGET, "target", "#19966e")):
if x is not None:
fig.add_vline(x=x, line=dict(color=col, dash="dash"), annotation_text=name)
fig.update_layout(xaxis_title=V, yaxis_title="density", bargap=0)
fig.show()Needs pandas, numpy, plotly, scipy · reads capability-histogram-demo.csv · app theme from the optional codesplash helper
# Process capability — Codesplash Chart Lab (recipe "capability-histogram")
# controls: lsl=9.95, usl=10.05, target=10
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("capability-histogram-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
v_col <- "diameter (mm)"
fx_col <- NULL
fd_col <- NULL
lsl <- 9.95; usl <- 10.05; target <- 10
v <- df[[v_col]][!is.na(df[[v_col]])]
edges <- seq(min(c(v, lsl, usl)), max(c(v, lsl, usl)), length.out = max(10, ceiling(log2(length(v)) + 1)) + 1)
fit <- if (!is.null(fx_col) && !is.null(fd_col)) stats::na.omit(data.frame(x = df[[fx_col]], y = df[[fd_col]])) else
data.frame(x = seq(min(edges), max(edges), length.out = 200), y = stats::dnorm(seq(min(edges), max(edges), length.out = 200), mean(v), stats::sd(v)))
lines <- data.frame(x = c(lsl, usl, target), name = c(if (!is.null(lsl)) "LSL", if (!is.null(usl)) "USL", if (!is.null(target)) "target"))
p <- ggplot(data.frame(v = v), aes(v)) +
geom_histogram(aes(y = after_stat(density)), breaks = edges, fill = cs_cat[1], alpha = 0.45, colour = "white") +
geom_line(data = fit, aes(x, y), colour = cs_cat[1], linewidth = 0.9) +
geom_vline(data = lines, aes(xintercept = x), colour = ifelse(lines$name == "target", "#19966e", "#ce5342"), linetype = "dashed") +
labs(x = v_col, y = "density") + theme_cs
print(p)Needs ggplot2 · reads capability-histogram-demo.csv · app theme from the optional codesplashr helper