torchcell.utils.savefig_true_size_svg

savefig_true_size_svg(fig: Figure, path: str, src_dpi: int = 72, drawio_dpi: int = 100, **savefig_kwargs: Any) → None[source]

Save a matplotlib figure as an SVG that imports at TRUE physical size in draw.io.

matplotlib writes SVG coordinates in PostScript points (72 per inch) and tags the root width/height with the pt unit. draw.io does not honor the CSS definition of pt; it reads the numeric width/height/viewBox in its own native unit of 100 per inch. A figure authored at W inches therefore imports at W * 72/100 inches – 72% of intended, fonts included (the source of the 57.7 mm-file / 41.4 mm-in-draw.io discrepancy).

This saves the SVG, then rewrites the root so the coordinate numbers correspond to drawio_dpi (100) per inch and wraps the drawn content in a matching scale() group. The rendered result is visually identical; only the declared coordinate system changes, so draw.io lands on the true mm/pt sizes and 6 pt text stays 6 pt.

For a fixed-figsize WYSIWYG canvas, do NOT pass bbox_inches="tight" – it recrops the canvas and defeats the intended size; author the figure at its final figsize instead. It IS appropriate for a standalone figure whose goal is a tight crop (e.g. a legend-only image); the rescale still yields a correct physical size for whatever tight box matplotlib emits.