Save and Validation¶
Save and preview¶
import dartwork_mpl as dm
import numpy as np
dm.style.use("scientific")
fig, ax = plt.subplots(figsize=dm.figsize("9cm", "standard"))
ax.plot(np.arange(50), np.cumsum(np.random.randn(50)) + 20, color="dc.ocean3")
dm.simple_layout(fig)
dm.save_formats(
fig,
"output/experiment",
formats=("png", "svg", "pdf"),
bbox_inches="tight",
validate=True, # runs visual checks before saving (see below)
)
dm.save_and_show(fig, "output/experiment") # save + inline preview
dm.show("output/forecast.svg", size=540) # display a saved file in notebooks
Key points:
save_formatswrites multiple formats in one call, with optional visual validationsave_and_showrenders a preview (matching the final saved output) and callsplt.show()showdisplays an existing SVG/PNG for notebooks or reportsSee API › Save & Export for argument details
Visual validation¶
Detect common rendering issues automatically — especially useful in AI agent pipelines where visual inspection is not available.
Tip
Try the live lint simulator that appears below this heading — slide
figure dimensions, tick counts, and label lengths to see exactly which
warnings dm.validate_figure() would emit. The same heuristics that ship
with the package are running in your browser.
import dartwork_mpl as dm
# Run all checks manually
warnings = dm.validate_figure(fig)
for w in warnings:
print(w)
# Run specific checks only
warnings = dm.validate_figure(fig, checks=('overflow', 'tick_crowding'))
When validate=True is passed to save_formats(), validation runs before
saving. If issues are found, they’re printed as warnings — the file is still
saved, but you’ll know what to fix.
Available checks: overflow detection, text overlap, legend overflow, tick crowding, and empty axes. Example output:
⚠ OVERFLOW: Text 'ylabel' extends beyond figure bounds by 3.2 pt
⚠ TICK_CROWDING: X-axis has 24 ticks in 3.5 inches (>6 per inch)
Static reference: every warning validate_figure() can emit¶
Plain-text fallback for the live lint simulator — useful when
JavaScript is disabled (AI agents, terminal browsers, search-engine
indexing). Each row is one check_id from dartwork_mpl/validate.py;
the Severity column is the default classification, and the Fix
column is the suggestion delivered by
dm.validate_with_fixes(fig) / dm.validate_fixes.get_fix_suggestions.
|
Severity |
What it detects |
Suggested fix |
|---|---|---|---|
|
warning |
Text or axes content extends past the figure edge |
Re-run |
|
warning |
Two text labels visually overlap |
Rotate, abbreviate, or split into multiple panels |
|
warning |
Legend extends past axes / figure edge |
Move legend outside via |
|
warning |
Tick labels overlap each other (>6 per inch) |
Reduce tick density ( |
|
info |
Axes carry no plotted artist |
Plot data or remove the empty axes via |
|
info |
Left / right or top / bottom margins differ a lot |
Re-run |
|
warning |
Pie wedge label sits outside its wedge |
Set |
|
warning |
A text artist is clipped at its axes boundary |
Disable clipping ( |
See API › Visual Validation for details.
See also¶
Next → Extended Plots & Diagnostics — ready-to-use plot templates and inspection tools
API › Save & Export for all save/export function arguments
Layout and Typography — optimize margins before saving