Skip to content

Plotting

tausurv.plot draws the figures of a survival analysis with matplotlib. Every function returns a Display dataclass holding the figure, the axes and the artists it created, so the figure can be changed afterwards with plain matplotlib.

PlotFunctionWhen
Kaplan-Meier curvests.plot.kmMarginal / per-group survival from raw data
Cumulative incidence (lines)ts.plot.cifCompeting risks, one cause per line
Cumulative incidence (stacked)ts.plot.stacked_cifCohort decomposition, stacks to 1
Predicted survivalts.plot.predicted_survivalS^(t∣x)\hat S(t \mid x) for one or many subjects
Risk stratificationts.plot.risk_strataKM by quantile of a continuous risk score
Forest plotts.plot.forestCoefficients / hazard ratios with CIs
Calibrationts.plot.calibrationPredicted vs observed at a horizon
AUC / C / Brier over timets.plot.auc_over_time etc.Evaluation curves with CV-fold bands
Copula diagnosticsts.plot.copula.contour etc.Joint CDF, density, samples
SHAP for survivalts.plot.shap.curves etc.Time-varying feature attributions

Every plot can be used at three levels, with the same parameter names:

  1. One call: ts.plot.km(event_time, event_indicator, group=arm) draws the figure and returns a Display.
  2. The Display: it carries .fig, .ax and plot-specific handles (.lines, .ci_polys, .at_risk_ax, …) for changing single elements.
  3. Matplotlib: .ax is an ordinary Axes.
  • Each function returns a <Name>Display dataclass, never a raw Axes.
  • Standard parameter names: ax, ci, ci_level, legend, xlabel, ylabel, title, color, label. Same defaults across plots.
  • Comparisons: group= for splitting raw subject data; models= for precomputed per-model overlays; a (n_estimates, n_times) values array for a mean and spread band over folds, resamples or runs.
  • Visual constants: CI bands at alpha=0.18, no edge, colour matched to the line. Reference lines at #888888, dashed, lw=0.6, alpha=0.6. Survival step plots use where="post". Legends are frameless.
  • Style: every plot picks up the active rcParams. Apply ts.plot.set_style("publication") once at the top of an analysis; plots never touch the style themselves.
  • Lazy import: import tausurv does not load matplotlib. Matplotlib loads lazily when the first plotting function is called.
  • Gallery: every plot, with the minimal code that draws it.
  • Styling: the four named styles, palette choices, font fallbacks, and how to override.