svgttt-plot
Total-time-on-test plot
Is the failure rate rising, falling, constant or bathtub-shaped?
How to read it
- Read x as the share of units failed and y as the share of total running time used by then.
- On the dashed diagonal the failure rate is constant, as an exponential lifetime requires.
- Bowed above means a rising failure rate (wear-out); bowed below means a falling one (early failures); an S shape suggests a bathtub.
- Callout 1: The curve above the diagonal: a rising failure rate.
- Callout 2: The diagonal: a constant failure rate.
- Callout 3: Which side means what.
Watch out
- It needs complete lifetimes. Units still running would need a censored version of this plot.
- With few failures the curve wanders around the diagonal by chance, so check the battery's p-values too.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Normalized spacings D_i = (n − i + 1)(x_(i) − x_(i−1)); the curve is (i/n, Σ_{j≤i} D_j / Σ D_j). Complete lifetimes only.
- The area statistic is the mean of the interior points, which equals one minus the Gini statistic.
# Total-time-on-test plot — Codesplash Chart Lab (recipe "ttt-plot")
# controls: defaults
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("ttt-plot-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_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")
V = "hours"
x = np.sort(df[V].dropna().to_numpy(dtype=float))
x = x[x > 0]
n = x.size
d = (n - np.arange(n)) * np.diff(x, prepend=0.0) # normalized spacings
u = np.concatenate(([0.0], np.arange(1, n + 1) / n))
ttt = np.concatenate(([0.0], np.cumsum(d) / d.sum()))
area = ttt[1:-1].mean()
fig, ax = plt.subplots(figsize=(6, 5))
ax.plot([0, 1], [0, 1], color=REF, linestyle="--", label="exponential (constant hazard)")
ax.plot(u, ttt, color=PALETTE[0], linewidth=1.8, label="TTT curve")
ax.set_xlabel("Share of units failed (i/n)")
ax.set_ylabel("Scaled total time on test")
ax.set_title(f"Scaled total-time-on-test plot: area {area:.3f}", fontsize=10, loc="left")
ax.legend(frameon=False)
plt.show()Needs pandas, numpy, matplotlib · reads ttt-plot-demo.csv · app theme from the optional codesplash helper
# Total-time-on-test plot — Codesplash Chart Lab (recipe "ttt-plot")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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("ttt-plot-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_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")
V = "hours"
x = np.sort(df[V].dropna().to_numpy(dtype=float))
x = x[x > 0]
n = x.size
d = (n - np.arange(n)) * np.diff(x, prepend=0.0) # normalized spacings
u = np.concatenate(([0.0], np.arange(1, n + 1) / n))
ttt = np.concatenate(([0.0], np.cumsum(d) / d.sum()))
area = ttt[1:-1].mean()
fig = go.Figure()
fig.add_scatter(x=[0, 1], y=[0, 1], mode="lines", line=dict(color=REF, dash="dash"), name="exponential (constant hazard)")
fig.add_scatter(x=u, y=ttt, mode="lines", line=dict(color=PALETTE[0]), name="TTT curve")
fig.update_layout(title=f"Scaled total-time-on-test plot: area {area:.3f}", xaxis_title="Share of units failed (i/n)", yaxis_title="Scaled total time on test")
fig.show()Needs pandas, numpy, plotly · reads ttt-plot-demo.csv · app theme from the optional codesplash helper
# Total-time-on-test plot — Codesplash Chart Lab (recipe "ttt-plot")
# controls: defaults
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("ttt-plot-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
v_col <- "hours"
x <- sort(df[[v_col]][!is.na(df[[v_col]]) & df[[v_col]] > 0])
n <- length(x)
d <- (n - seq_len(n) + 1) * diff(c(0, x)) # normalized spacings
curve <- data.frame(u = c(0, seq_len(n) / n), ttt = c(0, cumsum(d) / sum(d)))
area <- mean(curve$ttt[2:n])
p <- ggplot(curve, aes(u, ttt)) + geom_abline(slope = 1, intercept = 0, colour = ref_col, linetype = "dashed") +
geom_line(colour = cs_cat[1], linewidth = 0.8) +
labs(x = "Share of units failed (i/n)", y = "Scaled total time on test", title = sprintf("Scaled total-time-on-test plot: area %.3f", area)) + theme_cs
print(p)Needs ggplot2 · reads ttt-plot-demo.csv · app theme from the optional codesplashr helper