habit.viz: publication overlays
Publication figures and image overlays for HABIT results.
This package is the home for HABIT visualization: habitat-core figures
(overlays, partition triptych, auto-K curves, volume/MSI/ITH, label compare),
graph / voxel-texture panels, greyscale intensity slices for image
preprocessing (plot_intensity_slice()), habitat-clustering PCA,
optional napari (view_habitat_napari()), plus ROC / survival /
regression helpers.
New drawing / viewing code should land here rather than in CLI or
habit.api helpers.
Most functions in this package are PURE matplotlib helpers: they take contract
objects (or plain arrays), draw on a Figure, and return that figure.
Nothing here touches the filesystem – there is no savefig, no output-
directory parameter. Where a figure ends up is entirely the caller’s
decision. The optional napari helper is the one exception that may open a Qt
window; it still takes arrays only and never reads or writes image files.
Two consequences of that rule:
a figure’s geometry, typography and palette come from a STYLE PRESET (
use_style()), never from a per-plot hard-coding, so one figure can be re-rendered for a different journal without touching the plotting code;every piece of text drawn on a figure is guaranteed ASCII via
sanitize_label(), because data-driven labels (a feature or group name) can otherwise leak non-ASCII characters onto an axis that a journal will reject.
User guide: Habitat Guide Volume and fractions.
matplotlib is imported lazily inside each function, so importing
habit never pulls a plotting backend. All figure labels are
English-only.
Interactive overlay (needs napari):
view_habitat_napari(). Static PNG:
plot_habitat_overlay() (pass an ImageVolume so
coronal/sagittal keep superior up).
Classes
A named bundle of figure-geometry and typography choices. |
Functions
Style helpers
Apply a preset's rcParams for the duration of the block. |
|
Return the preset registered under |
|
Register a custom preset, making it usable by name in |
|
Return the registered preset names, sorted. |
|
Return |
Habitat clustering and overlay
Two-dimensional PCA scatter of habitat clustering units. |
|
Three-dimensional PCA scatter of habitat clustering units. |
|
Interactive 3D PCA scatter using plotly (optional dependency). |
|
Draw habitat labels as an opaque colour overlay on the source image. |
|
Plot auto-K / cluster-validation score curves (one panel per method). |
|
Draw validation curves from a habitat-model |
|
Bar chart of per-habitat volume fractions (of non-background VOI). |
|
Heatmap of a spatial interaction (MSI) matrix. |
|
One-panel bar chart: global ITH, then optional per-habitat ITH. |
|
Side-by-side habitat overlays, optional disagreement mask. |
|
Heatmap of the voxel-overlap table of two label maps of the same voxels. |
|
Habitat summaries of every subject, coloured by their shared prototype. |
|
Two-step partition view: greyscale | supervoxel overlay | habitat overlay. |
|
Draw per-feature ICC points with 95% CI whiskers. |
|
Habitat x feature heatmap (cohort mean or one subject). |
|
Habitat-pair effect sizes (Cliff's delta or Cohen's d). |
|
Habitat contrast on a few CVA or PCA component scores. |
|
Grouped violins (or box + strip when n is small) for a feature shortlist. |
|
One bar panel per feature (independent y-axis). |
|
Draw the colored habitat map at the largest cross-section (2D). |
|
Draw the intra/inter habitat graphs built from the 2D slice habitat map. |
|
Draw a subject x graph-feature heatmap (not habitat x texture). |
|
Render a 3D surface view of the habitat volume (PyVista). |
|
Render the 3D feature-aligned spatial graph on a dark scene (PyVista). |
|
Scatter one |
|
Display a whole-FOV greyscale anatomy / intensity slice. |
|
Display a voxel-level texture / feature map as 2D publication panels. |
|
Open (or populate) a napari viewer with image layer(s) + habitat labels. |
Ingestion and preprocessing diagrams
Teaching diagrams for the gallery: how data enters HABIT (directory tree, SimpleITK objects, NumPy arrays, NIfTI file pairs) and how clustering features are preprocessed. The right-hand panel is a real cropped data view.
Diagram for the directory-ingestion route: tree -> Subject with ROI. |
|
Diagram for the SimpleITK route: voxel-cube badge -> habitat overlay. |
|
Diagram for the array route: the data itself drawn as a colour matrix. |
|
Diagram for the file-pair route: |
|
Diagram of the clustering-feature preprocessing chain. |
Supporting plots (survival / classification / SHAP)
Bookmarks for table-ML figures. Not the habitat core.
Kaplan-Meier curves, optionally stratified, with a numbers-at-risk table. |
|
Three-panel risk-stratification figure. |
|
Uno's cumulative/dynamic AUC as a function of follow-up time. |
|
Calibration of the predicted horizon survival against Kaplan-Meier truth. |
|
Brier score of the predicted survival function across follow-up time. |
|
Forest plot of hazard ratios with 95% confidence intervals (log scale). |
|
Predicted-against-observed scatter with the identity line. |
|
Residuals against fitted values, to expose heteroscedasticity and bias. |
|
Quantile-quantile plot of the residuals against a normal reference. |
|
Bland-Altman limits-of-agreement plot. |
|
Forest-style plot of regression coefficients with optional CIs. |
|
Receiver-operating-characteristic curve(s) with AUC in the legend. |
|
Precision-recall curve(s) with average precision in the legend. |
|
Reliability diagram (calibration curve) against the identity line. |
|
Decision-curve analysis with Treat-All / Treat-None references. |
|
Confusion-matrix heatmap for discrete class predictions. |
|
Beeswarm-style SHAP summary for one attribution matrix. |
|
Global mean-absolute SHAP bar chart ( |
|
Violin-style SHAP summary ( |
|
Instance x feature SHAP heatmap ( |
|
SHAP dependence plot for one feature (pure; no filesystem). |
|
Per-sample SHAP waterfall explanation (pure; no filesystem). |
|
SHAP decision paths for a handful of samples. |
|
Static matplotlib force plot for one sample. |
|
Horizontal bar chart of permutation importances (pure; no filesystem). |
|
Rank features by mean absolute SHAP attribution (descending). |
|
Pick sample indices spanning the score range (low / mid / high). |
|
Decision-curve net benefit at one threshold probability. |