Matplotlib styles for science
Project description
matplotlabs
Matplotlib style sheets and colormaps for scientific publications.
matplotlabs gives you publication-ready defaults for figures — clean sans-serif
fonts, trimmed spines, constrained layout, and carefully designed color palettes —
so you can focus on the science instead of the formatting.
Installation
pip install matplotlabs
For development:
pip install matplotlabs[dev]
Quick start
import matplotlabs as mpll # registers styles, colormaps, and named colors on import
import matplotlib.pyplot as plt
plt.style.use("mpll")
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])
ax.set_xlabel("x")
ax.set_ylabel("y")
fig.savefig("figure.pdf")
That's it. The mpll style applies publication-ready defaults — sans-serif fonts
(Arial/Helvetica), 3.5 in single-column width, 7 pt font size, no top/right spines,
inward ticks, constrained layout, and PDF output.
Styles
Styles are composable — stack them in any order with plt.style.use([...]).
| Style | Description | Usage |
|---|---|---|
mpll |
Default scientific style. Sans-serif (Arial/Helvetica), 3.5 in width, 7 pt fonts, no top/right spines, inward ticks, 8-color qualitative cycle, constrained layout, PDF save. | plt.style.use("mpll") |
qualitative |
Explicit 8-hue qualitative color cycle at mid-saturation. Same as the default cycle — use when you want to apply the palette without the full base style. | plt.style.use("qualitative") |
latex |
LaTeX text rendering modifier. Enables text.usetex with Helvetica via helvet + sfmath. Requires a LaTeX installation. |
plt.style.use(["mpll", "latex"]) |
Composition examples
# Default style with LaTeX rendering
plt.style.use(["mpll", "latex"])
# Just the default style
plt.style.use("mpll")
# Only the color cycle, nothing else
plt.style.use("qualitative")
Named colors
All colors use the mpll: prefix (similar to tab:blue) and work anywhere
matplotlib accepts a color string. Each hue family has 6 shades numbered
1 (lightest) to 6 (darkest). The unadorned name maps to shade 4.
| Family | mpll:{name} (shade 4) |
Shades 1-6 |
|---|---|---|
lightone |
#A5A083 |
warm cream to dark khaki |
grey |
#6E788D |
light grey to dark slate |
red |
#C5373D |
light pink to dark red |
blue |
#006EAE |
light blue to dark navy |
yellow |
#CA9B23 |
light yellow to dark amber |
olive |
#96A00A |
light lime to dark olive |
green |
#429130 |
light green to dark green |
teal |
#0096A0 |
light teal to dark teal |
purple |
#A1478E |
light lavender to dark purple |
orange |
#E26600 |
light peach to dark orange |
skin |
#8D6651 |
light beige to dark brown |
Usage
import matplotlabs as mpll
import matplotlib.pyplot as plt
plt.style.use("mpll")
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4], color="mpll:red") # shade 4 (default)
ax.plot([0, 1, 2], [4, 1, 0], color="mpll:blue1") # lightest blue
ax.axhline(2, color="mpll:grey6") # darkest grey
Programmatic access
mpll.colors["red"] # ['#F6CECA', '#E9A0A5', '#DC6464', '#C5373D', '#9B241C', '#730C0D']
mpll.colors["lightone"] # ['#F6F2EE', '#E0DCCA', '#C5C1A5', '#A5A083', '#888364', '#5E5948']
Colormaps
All colormaps use the mpll- prefix and are registered automatically on import.
Each colormap also has a reversed variant with the _r suffix.
Sequential
| Colormap | Colors |
|---|---|
mpll-red |
light pink to dark red |
mpll-blue |
light blue to dark navy |
mpll-teal |
light teal to dark teal |
mpll-green |
light green to dark green |
mpll-yellow |
light yellow to dark amber |
mpll-orange |
light peach to dark orange |
mpll-purple |
light lavender to dark purple |
mpll-grey |
light grey to dark slate |
mpll-olive |
light lime to dark olive |
mpll-lightone |
warm cream to dark khaki |
mpll-skin |
light beige to dark brown |
Diverging
| Colormap | Description |
|---|---|
mpll-red-blue |
Red ← white → blue |
mpll-orange-teal |
Orange ← white → teal |
mpll-purple-green |
Purple ← white → green |
Usage
import matplotlabs as mpll
import matplotlib.pyplot as plt
import numpy as np
data = np.random.randn(10, 10)
fig, ax = plt.subplots()
im = ax.imshow(data, cmap="mpll-red-blue")
fig.colorbar(im, ax=ax)
# Reversed variant
im2 = ax.imshow(data, cmap="mpll-red-blue_r")
Utilities
annotate_heatmap
Overlay formatted numbers on each cell of a heatmap with automatic text color contrast (dark text on light cells, light text on dark cells).
import matplotlabs as mpll
import matplotlib.pyplot as plt
import numpy as np
plt.style.use("mpll")
data = np.array([[1.0, -0.5, 0.3], [-0.8, 0.001, 2500]])
fig, ax = plt.subplots()
im = ax.imshow(data, cmap="mpll-red-blue")
mpll.annotate_heatmap(im, data)
fig.colorbar(im, ax=ax)
fig.savefig("heatmap.pdf")
Parameters:
im— TheAxesImagereturned byax.imshow().data— The 2-D numpy array used to create the image.fmt— Explicit format string (e.g."{:.2f}"). WhenNone, each cell auto-selects between fixed-point, scientific notation, or integer formatting.sci_threshold— Magnitude threshold for scientific notation (default1e3).fontsize— Annotation font size. Defaults torcParams["font.size"] - 1.textcolors— Tuple of(low_color, high_color)for contrast. Default("black", "white").threshold— Colormap midpoint for switching text color. Defaults to(vmin + vmax) / 2.
Default style (mpll)
The mpll style sets these key rcParams:
| Parameter | Value |
|---|---|
| Font family | Sans-serif (Arial, Helvetica) |
| Font size | 7 pt |
| Figure size | 3.5 x 2.5 in |
| Figure DPI | 450 |
| Save DPI | 300 |
| Save format | |
| Spines | Bottom + left only |
| Ticks | Major only, inward, no minor |
| Layout | Constrained layout |
| Legend | No frame, 6 pt |
| Grid | Off |
| Marker size | 3 |
| Color cycle | 8 hues at mid-saturation |
Development
# Clone and install in editable mode
git clone https://github.com/lvvittor/matplotlabs.git
cd matplotlabs
pip install -e ".[dev]"
# Run tests
pytest
# Lint and format
ruff check .
ruff format .
# Generate example figures
python examples/plot.py
License
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matplotlabs-0.2.0.tar.gz.
File metadata
- Download URL: matplotlabs-0.2.0.tar.gz
- Upload date:
- Size: 52.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96c4d756385d21f0f86f96554f3b5ff2fce52ed5e0bc40fcc8969c6f94353644
|
|
| MD5 |
aa2974ce9f8ddbe5283504dc717b1216
|
|
| BLAKE2b-256 |
0dbdeffe83fcade178b45cf4ca3302fd4b9084474efc4d65b4054d90ea893a97
|
Provenance
The following attestation bundles were made for matplotlabs-0.2.0.tar.gz:
Publisher:
release.yml on lvvittor/matplotlabs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matplotlabs-0.2.0.tar.gz -
Subject digest:
96c4d756385d21f0f86f96554f3b5ff2fce52ed5e0bc40fcc8969c6f94353644 - Sigstore transparency entry: 954330059
- Sigstore integration time:
-
Permalink:
lvvittor/matplotlabs@9ef305d0ea2a5748e00acaae139010c7631ab96a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lvvittor
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9ef305d0ea2a5748e00acaae139010c7631ab96a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file matplotlabs-0.2.0-py3-none-any.whl.
File metadata
- Download URL: matplotlabs-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f50417f8c4e02ea81dd5649e1c87c164e67727e77690c558167fe3c2018fd84f
|
|
| MD5 |
5292e8e5e7826161e6b75e594d57fc36
|
|
| BLAKE2b-256 |
c74f30921748166d4ec2a204197aea375b0c85cc85e92cc67c31041a8ec29806
|
Provenance
The following attestation bundles were made for matplotlabs-0.2.0-py3-none-any.whl:
Publisher:
release.yml on lvvittor/matplotlabs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matplotlabs-0.2.0-py3-none-any.whl -
Subject digest:
f50417f8c4e02ea81dd5649e1c87c164e67727e77690c558167fe3c2018fd84f - Sigstore transparency entry: 954330060
- Sigstore integration time:
-
Permalink:
lvvittor/matplotlabs@9ef305d0ea2a5748e00acaae139010c7631ab96a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lvvittor
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9ef305d0ea2a5748e00acaae139010c7631ab96a -
Trigger Event:
workflow_dispatch
-
Statement type: