Templates for customizing layouts and styles of Matplotlib figures
Project description
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 ofplatformdirs
). - The
figure_templates/stylesheets
directory in the current working directory, or thestylesheets
directory within the directory specified by theMPL_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 ofplatformdirs
). - The
figure_templates/layouts
directory in the current working directory, or thelayouts
directory within the directory specified by theMPL_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 for examples of usage.
Using the default template print_fullwidth
:
Using the default template print_aside
:
Using the default template slide_square
:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mpl_figure_templates-0.1.0.tar.gz
.
File metadata
- Download URL: mpl_figure_templates-0.1.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42ba22dc3520de27ccbadf17e94d7da5d0d2b3e7bba7448162548b4ed7e18bdd |
|
MD5 | 2f103cafedb5b83179f2aade3fc490ad |
|
BLAKE2b-256 | edcfe91e8e3a942c01d1f2ca2d8d9f2caf51b3b10a45f8d90fb0df1af802e875 |
File details
Details for the file mpl_figure_templates-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: mpl_figure_templates-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c54bad972ab9fb331f3ff2d537aca3576811fac499709a0fe6038129cb57d283 |
|
MD5 | f806b639443dccf65707da2deb3871c4 |
|
BLAKE2b-256 | 2fea8e016fbdbf294edcd912598404496d69e4d36c4bd09d8f7582fc77e94fca |