Skip to content

Figure API

Examples assume import matplotlib.pyplot as plt and import hedgehogs as hdg. Configure shared typography and physical figure dimensions. Create figures with Matplotlib; adjust and export them through plots.

API index

API Purpose Returns
hdg.set_style(...) Configure global presentation defaults None
hdg.reset_style() Restore Matplotlib defaults and methods None
hdg.figsize(...) Read physical figure dimensions (width, height)
hdg.figures.align(figures) Match plotting boxes across separate figures None

Styling and layout

set_style

Apply global Matplotlib presentation defaults and enable proportional sizing for newly created figures.

hdg.set_style(
    base_fontsize=10.5, linewidth=1.1, figsize=(2.24, 2.20),
    subplot_margins=None, use_tex=False, scale_on_setup=False,
    scale_exponent=0.5, palette="okabe-ito",
)
Parameter Type Default Constraint or meaning
base_fontsize float 10.5 Body-text size in points before optional width scaling
linewidth float 1.1 Base stroke width before optional scaling
figsize tuple[float, float] (2.24, 2.20) Reference canvas width and height in inches
subplot_margins mapping or None None Override the default left, bottom, right or top fractions. Passing a mapping disables automatic Hedgehogs margin fitting.
use_tex bool False Enable Matplotlib TeX rendering
scale_on_setup bool False Apply initial width-based scaling. Automatic resizing operates independently.
scale_exponent float 0.5 Exponent used for width-based scaling when scale_on_setup=True
palette str "okabe-ito" Registered palette name

Filled markers receive black outlines unless overridden; unfilled markers use one stroke colour. New single panels scale relative to figsize, while grids retain configured point sizes. See Presentation rules.

reset_style

Stop automatic figure sizing and restore Matplotlib defaults.

hdg.reset_style() -> None
hdg.set_style(palette="okabe-ito")
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])
hdg.plots.show(fig=fig)
hdg.reset_style()

figsize

Read starting canvas dimensions in inches.

hdg.figsize(name="science", column="single") -> tuple[float, float]
Preset Single-column size Double-column size
nature 3.50 × 2.65 in 7.20 × 4.80 in
science 2.24 × 2.20 in 4.76 × 3.40 in
ieee 3.50 × 2.55 in 7.16 × 4.80 in
aps 3.40 × 2.60 in 7.00 × 4.80 in

name defaults to "science" and column to "single"; names ignore case. Unknown selections raise ValueError. Dimensions are starting points; check the target journal's requirements. Typography is configured separately through set_style().

Create figures and axes with Matplotlib:

size = hdg.figsize("science", "double")
hdg.set_style(figsize=size)
fig, axes = plt.subplots(2, 2, figsize=size, layout="constrained")

Use Matplotlib's gridspec_kw, sharex, sharey and layout for panel geometry. For colour bars and nested axes, select layout="constrained"; hdg.plots.square(ax=ax) gives a square plotting box.

figures.align

Match the position and physical size of plotting boxes across separate figures. Supply an iterable of at least two distinct Matplotlib figures with the same figsize.

hdg.figures.align(figures) -> None

In this example, x_input contains the shared sample positions, each Phi_* array contains one response per sample and FIG_SIZE is the common width and height in inches.

figures = []
for values, title in [(Phi_gaussian, "Gaussian RBF"), (Phi_matern, "Matern C4 RBF"), (Phi_homemade, "Homemade C4 RBF")]:
    fig, ax = plt.subplots(figsize=FIG_SIZE)
    ax.plot(x_input, values)
    ax.set(xlabel="x", ylabel="y", title=title)
    figures.append(fig)

hdg.figures.align(figures=figures)
for fig, name in zip(figures, ["gaussian", "matern", "homemade"]):
    hdg.plots.save(f"{name}.png", fig=fig, transparent=True)
hdg.plots.show()

Alignment finishes each figure, shares the largest fitted margins and checks that labels fit. Automatic x/y axis labels on the same side share an anchor position; padding increases where needed. Positions explicitly set with set_label_coords() remain unchanged. Canvas dimensions, data limits, ticks and palettes are preserved.

Supports one rectilinear panel per figure without fixed aspect ratios, colourbars, inset axes, figure-level text or figure legends. Unsupported inputs raise an error. If fitting fails, increase figsize or simplify labels. Returns None.

Align after adding data and labels, before saving. Earlier files are not updated. Reapply after changing content, layout or canvas size; resizing releases that figure's alignment. PNG, PDF and SVG exports retain the common plotting box, although tight cropping can produce different outer file dimensions. Figures outside the supplied sequence are unaffected.

Palettes

See Palettes and series styles for colour selection, series mapping and custom palette APIs.

Specialised plots

See Plots for drawing, panel labels, square boxes, legends and output.