Examples · Plots
waterfall_svg
The same figure as a dependency-free SVG string, for decision letters, case files and PDFs.
Code#
waterfall_svg.py
import pathlib from _setup import artifact, row from compileml.runtime import decidefrom compileml.viz import waterfall_svg decision = decide(artifact, row, include_contributions=True)# Wider than the 760px default, and fewer bars than the ten-feature default.# Impact labels are placed to the right of each bar without checking the# canvas edge, so a bar that ends near the right runs its label off the# figure. Widening does not fix it — the overflow scales with the width —# so this is chosen to fit these bars rather than to be correct in general.# Reported upstream.svg = waterfall_svg(decision, max_features=6, width=1200) pathlib.Path("../../public/examples/waterfall_svg.svg").write_text(svg, encoding="utf-8") print("baseline + impacts sum exactly to the score the runtime returned.")print()print("band ", decision["band"])print("latent_int ", decision["latent_int"])print("svg bytes ", len(svg))print()print("The renderer imports nothing outside the standard library, so the")print("plot can be produced in the same constrained environment as the score.")Output#
Captured from an actual run against compileml 0.9.0 and the UCI credit panel. If this script stops working, the build fails.
captured in CIwaterfall_svg.py
baseline + impacts sum exactly to the score the runtime returned. band G09latent_int 341svg bytes 3027 The renderer imports nothing outside the standard library, so theplot can be produced in the same constrained environment as the score.Figure#
Rendered by the run above, from the decision payload rather than a recomputation.
Notes#
- No matplotlib required — this path is importable anywhere the runtime is.