Paper Figure Exporter

Overview

Use drcutils.viz.export_figure to export Matplotlib figures with publication-friendly presets and consistent output naming.

Quick Start

import matplotlib.pyplot as plt
from drcutils.viz import export_figure

fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4], label="trend")
ax.set_xlabel("Time")
ax.set_ylabel("Score")
ax.legend()

result = export_figure(
    fig,
    "artifacts/figures/main_result",
    targets=["one_col", "slide_16x9"],
    formats=["pdf", "png"],
    dpi=300,
)

print(result["files"])
print(result["warnings"])

API Reference

Utilities for exporting paper-ready Matplotlib figures.

drcutils.viz.paper_figures.export_figure(fig, outpath_stem, *, targets=None, formats=None, dpi=300, transparent=False, tight=True, font_family=None, base_fontsize=None, embed_fonts=True, metadata=None)[source]

Export a Matplotlib figure for publication presets.

Parameters:
  • fig – Matplotlib figure object to export.

  • outpath_stem – Base output path stem.

  • targets – Preset targets to render.

  • formats – Output formats such as pdf, png, or svg.

  • dpi – Raster resolution for bitmap outputs.

  • transparent – Whether to export with transparent background.

  • tight – Whether to save with tight bounding boxes.

  • font_family – Optional font family override.

  • base_fontsize – Optional base font size override.

  • embed_fonts – Whether to configure embedded/export-friendly fonts.

  • metadata – Optional metadata mapping passed to savefig.

Returns:

A dictionary containing generated file paths, resolved settings, and warnings.

drcutils.viz.paper_figures.get_figure_preset(target)[source]

Return figure preset settings for a named target.

Parameters:

target – One of one_col, two_col, or slide_16x9.

Returns:

A dictionary with width, height, and font scale.

Raises:

ValueError – If target is unknown.