SpiffyPlots
A collection of opinionated matplotlib style sheets and plotting tools for publication-ready figures.
Requires Python 3.10 or newer and matplotlib 3.8 or newer.
- Free software: MIT license
- Documentation (likely not up to date): https://spiffyplots.readthedocs.io.
Installation
Install the latest release:
pip install spiffyplots
or install the latest commit directly from GitHub:
pip install git+https://github.com/JRBCH/spiffyplots.git
Using the style sheets
Import spiffyplots and load the default spiffy style to get more sensible default plotting parameters across the board.
What does it do?
Life is too short to look at ugly figures. This style fixed that problem for me, and over time I added a bunch of quality-of-life features to it, such as:
- Editable vector text by default. PDF and PostScript files embed TrueType fonts, and SVG retains
<text>elements instead of converting glyphs to paths. - Sensible default colors, fonts, and font sizes.
- Zero outer padding for better control over the final figure size.
Combining style sheets
The base spiffy style contains my own rather opinionated preferences for everyday use. You can combine it with other style sheets to match it to your use case.
import matplotlib.pyplot as plt
import spiffyplots
plt.style.use("spiffy") # base style only
plt.style.use(["spiffy", "tol-muted"]) # plus a color scheme
plt.style.use(["spiffy", "nature"]) # plus a journal-specific style
[!NOTE] Import
spiffyplotsbefore callingplt.style.use. The import registers the style sheets.
What styles are included?
| Type | Styles |
|---|---|
| Base | spiffy |
| Color | tol-bright, tol-high-contrast, tol-light, tol-medium-contrast, tol-muted, tol-vibrant, okabe-ito |
| Modifiers | latex, latex-helvetica, minor-ticks, right-axis, top-axis |
| Journals (beta) | cell, elife, jmlr, jneurosci, nature, neuron, plos-compbiol, science, tmlr |
Why journal-specific style sheets?
Because journal guidelines are oddly specific and differ in some important details (e.g. whether a double-column figure is 175mm or 183mm wide), and I wanted a set-and-forget way of defining the journal style once, so I can focus on the actual data visualization. The API for this might change in future releases.
How to use Journal-specific styles:
Journal styles automatically apply journal guidelines.
They set a default figure dimension (double column by default), correct font sizes for all plot elements, and export resolution.
Some features, such as different figure size options, can instead be accessed through the spiffyplots.journals module.
For example, spiffyplots.journals.nature.single_column(height=65, unit="mm") returns a figure size in inches that matches Nature's single-column figure guidelines with your specified height.
Multi-Panel figures
matplitlib's GridSpec is great, but I got real tired of formatting and re-formatting panel alignments. MultiPanel is my attempt of making this process easier.
import matplotlib.pyplot as plt
from spiffyplots import MultiPanel
plt.style.use("spiffy")
figure = MultiPanel(
grid=[4, 2], # 4 panels in the first row, 2 in the second
labels=True, # label panels (a, b, c, ...)
)
# Access each subplot axis by its label
figure.panels.a.hist(data)
figure.panels.b.scatter(x1, x2)
(...)
See examples/ex_multipanel.py for the full example and a comparison to the default matplotlib style.
There are many other ways to define MultiPanel layouts, label placements, grid arrangements etc, see the example notebook for a short tutorial.
[!NOTE] Since I wrote this module, matplotlib has added
subplot_mosaic, which solves a very similar problem. I may reworkMultiPanelto wrap that instead ofGridSpecone day, or stop using it all together, but for now I still prefer the spiffy interface.
Colors and colormaps
Style sheets only set the default cycle. For easy access to sensible colors, I use spiffyplots.colors for discrete colors and spiffyplots.cmap for colormaps.
I really love Paul Tol's color schemes, so I heavily rely on them.
import spiffyplots as spiffy
scheme = spiffy.colors.tol_vibrant
color1 = scheme.red # '#CC3311'
color2 = scheme.blue # '#0077BB'
spiffy.colors.from_cmap(spiffy.cmap.sequential, 6) # 6 equally spaced colors
spiffy.colors.shades(color1, 5) # 5 shades of one base color
Schemes: tol_bright, tol_high_contrast, tol_vibrant, tol_muted,
tol_medium_contrast, tol_light, tol_pale, tol_dark and okabe_ito.
Each is a tuple you can index, slice and iterate, whose colors are also
reachable by name. Each runs in its author's recommended order, then black,
then grey.
Colormaps
Again, I wrapped Paul Tol's colormaps together with the default matplotlib colormaps in a convenient way for access & modification:
cmap = spiffy.cmap.sequential # default sequential colormap (Paul Tol's iridescent)
cmap = spiffy.cmap.diverging # default diverging colormap (Paul Tol's nightfall)
cmap = spiffy.cmap.iridescent_r # a specific colormap, reversed
cmap = spiffy.cmap.viridis # falls through to matplotlib
You can also create colormaps from one or more base colors:
cmap = spiffy.cmap.from_base(color1) # white -> color -> darker color
cmap = spiffy.cmap.from_colors(spiffy.colors.tol_muted)
Perceptually uniform colormaps
cmcrameri and
Colorcet do this exceptionally well,
and spiffy.cmap can access their colormaps once either is installed.
To install them together with spiffyplots:
pip install "spiffyplots[colormaps]"
You can then access them through spiffy.cmap as well:
import spiffyplots as spiffy
cmap = spiffy.cmap.batlow # cmcrameri, registered as `cmc.batlow`
cmap = spiffy.cmap.kbc # colorcet, registered as `cet_kbc`
Credits
-
Most color schemes are Paul Tol's, redistributed under the 3-clause BSD license.
-
Shoutout to cmcrameri and Colorcet for their beautiful perceptually uniform colormaps.
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 spiffyplots-0.8.0.tar.gz.
File metadata
- Download URL: spiffyplots-0.8.0.tar.gz
- Upload date:
- Size: 559.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a597525a9fdac0ed05320a106a8bb806b1d376091e78417a3e737859c7f4f9b5
|
|
| MD5 |
f0727b5d203519cb6038a05e044d9356
|
|
| BLAKE2b-256 |
f01cc8ee8fe84f6ba78713256faabd9f8c053b785b8b648080ed9b9f1b1bc2d2
|
Provenance
The following attestation bundles were made for spiffyplots-0.8.0.tar.gz:
Publisher:
publish.yaml on JRBCH/spiffyplots
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spiffyplots-0.8.0.tar.gz -
Subject digest:
a597525a9fdac0ed05320a106a8bb806b1d376091e78417a3e737859c7f4f9b5 - Sigstore transparency entry: 2369537522
- Sigstore integration time:
-
Permalink:
JRBCH/spiffyplots@85d18e5d9c00ccec27df1949310d7e1a2cb83c72 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/JRBCH
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@85d18e5d9c00ccec27df1949310d7e1a2cb83c72 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spiffyplots-0.8.0-py3-none-any.whl.
File metadata
- Download URL: spiffyplots-0.8.0-py3-none-any.whl
- Upload date:
- Size: 46.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
748301dba6843a50cf16fc9a462ed504b44b302203b9c79ab833e7d493d4dcd8
|
|
| MD5 |
806edcec39572a3df758158d312d8310
|
|
| BLAKE2b-256 |
b34dfb17adc3b0d88240c3c9ca17dff6dbaf9b568a055045658733f1f596726c
|
Provenance
The following attestation bundles were made for spiffyplots-0.8.0-py3-none-any.whl:
Publisher:
publish.yaml on JRBCH/spiffyplots
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spiffyplots-0.8.0-py3-none-any.whl -
Subject digest:
748301dba6843a50cf16fc9a462ed504b44b302203b9c79ab833e7d493d4dcd8 - Sigstore transparency entry: 2369537826
- Sigstore integration time:
-
Permalink:
JRBCH/spiffyplots@85d18e5d9c00ccec27df1949310d7e1a2cb83c72 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/JRBCH
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@85d18e5d9c00ccec27df1949310d7e1a2cb83c72 -
Trigger Event:
push
-
Statement type: