Skip to main content

SpiffyPlots

Tests Documentation Status PyPI version GitHub last commit MIT license

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.

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.

spiffyplots demo

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 spiffyplots before calling plt.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)
(...)

multipanel example

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 rework MultiPanel to wrap that instead of GridSpec one 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

spiffyplots-0.8.0.tar.gz (559.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spiffyplots-0.8.0-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

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

Hashes for spiffyplots-0.8.0.tar.gz
Algorithm Hash digest
SHA256 a597525a9fdac0ed05320a106a8bb806b1d376091e78417a3e737859c7f4f9b5
MD5 f0727b5d203519cb6038a05e044d9356
BLAKE2b-256 f01cc8ee8fe84f6ba78713256faabd9f8c053b785b8b648080ed9b9f1b1bc2d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for spiffyplots-0.8.0.tar.gz:

Publisher: publish.yaml on JRBCH/spiffyplots

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for spiffyplots-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 748301dba6843a50cf16fc9a462ed504b44b302203b9c79ab833e7d493d4dcd8
MD5 806edcec39572a3df758158d312d8310
BLAKE2b-256 b34dfb17adc3b0d88240c3c9ca17dff6dbaf9b568a055045658733f1f596726c

See more details on using hashes here.

Provenance

The following attestation bundles were made for spiffyplots-0.8.0-py3-none-any.whl:

Publisher: publish.yaml on JRBCH/spiffyplots

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 files

0.7.0

2 files

0.6.1

1 file

0.6.0

1 file

0.5.1

2 files

0.4.5

1 file

0.4.4

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1

1 file

0.4.0

1 file

0.3.12

1 file

0.3.11

1 file

0.3.10

2 files

0.3.9

2 files

0.3.7

1 file

0.3.6

1 file

0.3.5

1 file

0.3.4

1 file

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

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