The figure, plug and play#
Every clip figure in this repository comes from one self-contained file, ways/figure.py (numpy
and matplotlib only). Copy it into any Python project and call it with your own audio, your own
degradation detector and your own attribution method.
from ways.figure import ways_figure
ways_figure(
wav, 16000, # mono waveform, any length
quality=probs, quality_hop=0.02, # any detector: [frames, classes] probabilities, seconds per frame
quality_classes=["noise", "music", "reverb"],
models=[{"name": "my-asr", "tokens": ["hello", "world"],
"top": [(2, 14), (3, 20)], # per word: (band, time index) of the audio patch it used most
"patch_s": 0.1, "n_bands": 8, "wer": 0.1}],
window=None, # or known damaged spans, counted against instead of the detector
text={"title": "my clip", "x_time": "seconds", "caption": "my own caption"}, # any heading, axis name or sentence
style={"width_in": 10, "font_size": 11}, # colours, fonts, sizes
out="my_clip.png") # PNG at 300 dpi plus an SVG twin
Three rules are enforced in code:
Every string is data. Headings, lane titles, axis names, verdict sentences and the caption are fields of
FigureTextandLatentText, and colours and sizes are fields ofFigureStyle.Text never overlaps. Labels are placed from measured text widths. After drawing, every text box is checked against every other and against the page edge, and the function raises
LayoutErrorinstead of writing a bad figure.The same inputs give the same bytes. The font is bundled, the SVG hash salt is fixed and the metadata carries no dates. A test compares the SHA-256 of two runs.