Skip to main content

Figures templates for Matplotlib

Templates for figure layout, styles, and axes.

The templates are designed to create consistent figure layouts with minimal visual clutter. They are entirely customizable to fit your specific document formats. The layouts help you organize visual elements on a grid, with direct control of alignments and spacing.

Usage

import numpy as np
from figure_templates import style, make_figure, set_axis

with style("slide"):
    fig = make_figure('slide_fullwidth')
    ax = fig.axes[0]

    x = np.linspace(0, 5, 100)
    ax.plot(x, np.sin(x), marker='.', markevery=15, clip_on=False)

    set_axis(ax, 'x', major_ticks=[0,5], minor_ticks=range(5))
    set_axis(ax, 'y', major_ticks=[-1, 0, 1], minor_ticks=np.arange(-1, 1, 0.5))

    ax.set_xlabel('Time')
    ax.set_ylabel('Periodic signal')

Adding Custom Stylesheets

To add custom stylesheets, create a .mplstyle file and place it in one of the following directories:

  • The mpl_figure_templates/stylesheets directory in the platform-dependent user configuration directory (following conventions of platformdirs).
  • The figure_templates/stylesheets directory in the current working directory, or the stylesheets directory within the directory specified by the MPL_FIGURE_TEMPLATES_CONFIG_DIR environment variable. Environment variables can be set in a .env file in the current working directory.

Stylesheets are added to matplotlib's style library and can be loaded using the with style("style_name") context manager. Styles are named after their file name. Configuration directories are read in order of priority, with the last directory taking precedence.

Alternatively, create a custom stylesheet as a matplotlib RcParams object and pass it to the style context manager.

Adding Custom Layouts

To add custom layouts, create a .yml file with the layout parameters and place it in one of the following directories:

  • The mpl_figure_templates/layouts directory in the platform-dependent user configuration directory (following conventions of platformdirs).
  • The figure_templates/layouts directory in the current working directory, or the layouts directory within the directory specified by the MPL_FIGURE_TEMPLATES_CONFIG_DIR environment variable. Environment variables can be set in a .env file in the current working directory.

Layouts are named after their file name. Configuration directories are read in order of priority, with the last directory taking precedence.

Example of a Custom Layout YAML File :

# Number of rows and columns in the figure
num_rows: 2
num_cols: 2

# Width and height of the figure in inches
fig_width: 8.0
fig_height: 6.0

# Base unit in points ; this unit is used for all other dimensions. If designing on a grid, this could be the size of a grid cell.
base_unit: 72

# Margins, in base units
margin_top: 0.5
margin_bottom: 0.5
margin_left: 0.5
margin_right: 0.5

# Horizontal and vertical separation between axes in base units
hsep: 0.5
vsep: 0.5

# Whether the figure is framed
is_framed: true

# Shift of the spines in base units, with respect to the axes
spine_shift: 0.2

# X-label position: a preset defined in figure_templates.axes, and padding between label and axes in base units
xlabel_preset: center
xlabel_pad: 0.5

# Y-label position: a preset defined in figure_templates.axes, and padding between label and axes in base units
ylabel_preset: top_right
ylabel_pad: 0.5

Alternatively, create a figure_templates.layouts.Layout object and use it as template argument in the make_figure function.

Samples

See the samples directory in the GitHub repository for examples of usage, with the default templates.

The package lets control axis ticks and relocate axis labels with minimal boilerplate:

Example print_aside

The provided templates are designed to create consistent figure layouts with minimal visual clutter.

Example print_fullwidth

A number of presets are provided to relocate x-axis and y-axis labels in various positions :

Examples of label positions

Metadata

Release files for mpl-figure-templates 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mpl-figure-templates 0.1.1
File Size Uploaded Provenance Actions
mpl_figure_templates-0.1.1.tar.gz 9.8 kB Without provenance Details for mpl_figure_templates-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mpl-figure-templates 0.1.1
File Interpreter ABI Platform Actions
mpl_figure_templates-0.1.1-py3-none-any.whl Python 3 none any Details for mpl_figure_templates-0.1.1-py3-none-any.whl

Total release size: 26.0 kB

Release files / mpl_figure_templates-0.1.1.tar.gz

Download URL mpl_figure_templates-0.1.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7032aa9a0864af14372a0ee7088980d4de941319320316bbfdadc8faf34e51f8
BLAKE2b-256 checksum
How to use checksums
da832a49828106e59ecd928a46ce0689502ffe3512610302d9aee9be00578df4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release files / mpl_figure_templates-0.1.1-py3-none-any.whl

Download URL mpl_figure_templates-0.1.1-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6152563b181b2e3b5d1c9c487c37ab5f5fb30a1d5b30863754e605e5c839277e
BLAKE2b-256 checksum
How to use checksums
8ab272c70127ae5ec80a6c9996f62672ab2304b28d728c2cdd130b8eabd61c91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Security for mpl-figure-templates 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page