API Reference

This page is generated from the public Python docstrings.

prepare

Install the LaTeX-side files for a document directory.

prepare(...) copies pubify.sty into destination and writes a pubify-template.tex file there using the provided template values.

Parameters:

Name Type Description Default
destination str | Path

Directory that should receive pubify.sty and pubify-template.tex.

required
template dict[str, Any] | None

Optional template dictionary used to generate pubify-template.tex.

None

Returns:

Type Description
tuple[Path, Path]

A pair (package_path, template_path) with the written file paths.

install_pubify_package

Copy pubify.sty into a document directory.

In normal use, prefer prepare(...), which installs both pubify.sty and pubify-template.tex together.

Parameters:

Name Type Description Default
destination str | Path

Directory that should receive pubify.sty, or an explicit .sty destination path.

required

Returns:

Type Description
Path

The written pubify.sty path.

write_tex_template

Write pubify-template.tex for a document template dictionary.

In normal use, prefer prepare(...), which writes the template file and installs pubify.sty in one step.

Parameters:

Name Type Description Default
path str | Path

Destination directory or explicit .tex file path.

required
template dict[str, Any] | None

Optional template dictionary. When omitted, the built-in default template is used.

None

Returns:

Type Description
Path

The written pubify-template.tex path.

pubify_rc_context

Apply the construction-time publication rc context implied by a pubify template.

save_fig

Export a copied Matplotlib figure or axes for a named LaTeX layout.

save_fig(...) normally never modifies the original figure in place. It clones the figure, applies publication styling and any requested cleanup to that copy, resizes the copy to fit the selected layout, and writes the exported file. Passing a Figure exports the full composed figure as one artifact. Passing an Axes exports only that axes panel, optionally keeping an attached colorbar. If skip_clone=True, export operates on the original figure. If filename has no suffix, .pdf is used by default.

Parameters:

Name Type Description Default
fig_or_ax Figure | Axes

matplotlib.figure.Figure to export as a full composed figure, or matplotlib.axes.Axes to export as a single panel.

required
layout str

Named layout such as "onewide", "twowide", or "four".

required
filename str | Path

Output path for the exported figure. If no suffix is given, .pdf is used. Relative paths are created if needed; absolute paths require an existing parent directory.

required
template dict[str, Any] | None

Optional template dictionary. Overrides any active use_template(...) context.

None
caption_lines int | None

Estimated number of lines in the main caption. Defaults to 1.

None
subcaption_lines int | None

Estimated number of lines in each subcaption. Defaults to 0.

None
force_width float | None

Optional width override in inches. Supported for non-wide layouts only and must still fit inside the chosen layout budget.

None
force_height float | None

Optional height cap in inches. The export is first sized normally for the chosen layout and then uniformly scaled down if it would otherwise exceed this height. On wide layouts, the default sizing uses the full layout width before this cap is applied.

None
force_aspect float | None

Optional aspect ratio override for the exported copy.

None
dpi int

Export DPI for the copied figure.

300
keep_titles bool

Keep axis titles on the copied figure instead of clearing them.

False
hide_labels bool

Remove axis labels and shared figure labels from the copied figure.

False
hide_annotations bool

Remove ax.text(...) annotations from the copied figure.

False
hide_ticks bool

Remove tick marks and tick labels from the copied figure.

False
hide_tick_labels bool

Remove tick labels while keeping tick positions.

False
hide_grid bool

Disable the grid on the copied figure.

False
hide_cbar bool

Remove attached colorbars and all colorbar axes from the copied figure.

False
skip_clone bool

Skip the pickle-clone step and export the original figure in place.

False
skip_rasterize bool

Disable the vector-output rasterization heuristic.

False
rasterize_scatter_threshold int

Collection-size threshold for auto-rasterizing scatter-like artists in vector outputs.

1000
rasterize_image_pixel_threshold int

Pixel-count threshold for auto-rasterizing image artists in vector outputs.

1000000
rasterize_line_vertex_threshold int

Vertex-count threshold for auto-rasterizing line artists in vector outputs.

2000
extra_rcparams dict[str, Any] | None

Additional Matplotlib rcParams applied during export.

None
prepare_export PrepareExportCallback | None

Optional callback that receives the figure object that will be exported after the standard cleanup/style pass and can make additional changes before rasterization and export sizing. For Figure input, this is the full composed figure copy. For Axes input, this is the isolated single-panel figure copy. When skip_clone=True, this may be the original figure. Callbacks may accept either prepare_export(fig_export) or prepare_export(fig_export, style), where style is a ResolvedStyle carrying the resolved publication styling values.

None
verbose bool

Print export diagnostics.

False

hide_labels

Remove x/y axis labels and shared figure labels on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose labels should be removed.

required

hide_annotations

Remove ax.text(...) annotations on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose text annotations should be removed.

required

hide_ticks

Remove tick locations and tick labels on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose ticks should be removed.

required

hide_tick_labels

Remove tick labels while preserving tick locations.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose tick labels should be cleared.

required

hide_grid

Disable gridlines on the selected axes.

Parameters:

Name Type Description Default
target Figure | Axes

Figure or axes that defines the traversal root.

required
axes Axes | Iterable[Axes] | None

Optional axes selection. When omitted, all axes in target are used.

None

hide_cbar

Remove colorbar axes attached to the selected axes.

Parameters:

Name Type Description Default
target Figure | Axes

Figure or axes that defines the traversal root.

required
axes Axes | Iterable[Axes] | None

Optional axes selection. When omitted, all axes in target are used.

None

remove_outside_padding

Best-effort removal of outer figure padding while preserving internal spacing.

This rescales and translates the full figure composition so the outer margin is reduced without recomputing the relative spacing among internal axes. It works best for composite figures built from multiple axes, manually added colorbar axes, and figure-level labels placed in figure coordinates. If you also align companion axes with match_axis_height(...) or match_axis_width(...), call those after remove_outside_padding(...).

Parameters:

Name Type Description Default
fig Figure

Figure whose outer padding should be reduced.

required
pad float

Optional figure-coordinate padding to leave on each outer edge.

0.0

match_axis_span

Match one axes span to another while preserving the orthogonal placement.

This is useful for manually positioned companion axes such as shared colorbars that should match the height or width of a reference data axes after layout tweaks or export-time adjustments. If you also call remove_outside_padding(...), do that first and then rematch the span.

Parameters:

Name Type Description Default
target_ax Axes

Axes whose span should be updated.

required
ref_ax Axes

Reference axes whose span should be matched.

required
axis str

Which span to match. Use "y" to match vertical position and height, or "x" to match horizontal position and width.

'y'

match_axis_height

Match a target axes height and vertical position to a reference axes.

If you also call remove_outside_padding(...), do that first and then call match_axis_height(...).

match_axis_width

Match a target axes width and horizontal position to a reference axes.

If you also call remove_outside_padding(...), do that first and then call match_axis_width(...).

force_font_family

Force a font family across figure text, labels, ticks, and legends.

Parameters:

Name Type Description Default
fig Figure

Figure whose text artists should be updated.

required
family str

Font family to apply.

PUBIFY_FONT_FAMILY

set_line_width

Set line width on lines and compatible collections.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose line-like artists should be updated.

required
line_width float

New stroke width.

required

set_spine_width

Set spine width on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose spines should be updated.

required
spine_width float

New spine stroke width.

required

set_tick_width

Set tick stroke width on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose ticks should be updated.

required
tick_width float

New tick stroke width.

required

set_tick_length

Set tick length on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose ticks should be updated.

required
tick_length float

New tick length.

required

set_axes_labelsize

Set x/y axis label and shared figure label font size.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose axis-label text should be updated.

required
axes_labelsize float

New axis-label font size.

required

set_tick_labelsize

Set tick label font size on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose tick labels should be updated.

required
tick_labelsize float

New tick-label font size.

required

set_legend_fontsize

Set legend text and title font size on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose legends should be updated.

required
legend_fontsize float

New legend text and title font size.

required

set_title_fontsize

Set axes title font size on a figure or axes tree.

Parameters:

Name Type Description Default
fig Figure | Axes

Figure or axes whose titles should be updated.

required
title_fontsize float

New title font size.

required

use_template

Temporarily set a default template for save_fig(...) calls.

Inside the with block, any save_fig(...) call that does not pass an explicit template=... argument will use this template.

Parameters:

Name Type Description Default
template TemplateSpec

Template dictionary to activate inside the context.

required