_common
tit.plotting._common ¶
Shared matplotlib helpers.
Goals: - Keep plotting code headless-safe (Docker/CI) without forcing backend changes at import-time. - Avoid importing matplotlib globally when not needed.
SaveFigOptions
dataclass
¶
SaveFigOptions(dpi: int = 600, bbox_inches: str = 'tight', facecolor: str = 'white', edgecolor: str = 'none')
Options forwarded to Figure.savefig.
Attributes¶
dpi : int
Resolution in dots per inch (default 600).
bbox_inches : str
Bounding-box mode passed to savefig (default "tight").
facecolor : str
Background colour of the saved figure (default "white").
edgecolor : str
Edge colour of the saved figure (default "none").
suppress_matplotlib_findfont_noise ¶
No-op: matplotlib.font_manager silencing is now handled by tit.logger.setup_logging() in its third-party quieting loop.
ensure_headless_matplotlib_backend ¶
ensure_headless_matplotlib_backend(backend: str = 'Agg') -> None
Best-effort backend setup for headless environments.
Important: - This should be called BEFORE importing matplotlib.pyplot. - If a backend is already active, we do not force-change it.
Source code in tit/plotting/_common.py
savefig_close ¶
savefig_close(fig: Any, output_file: str, *, fmt: str | None = None, opts: SaveFigOptions = SaveFigOptions()) -> str
Save a matplotlib Figure and close it.
Uses fig.savefig (not plt.savefig) to avoid relying on global pyplot state.