Skip to content

Opinionated matplotlib style kit with bundled DM Sans font, seaborn colorblind palette, and helpers for publication-ready benchmark plots.

License

Notifications You must be signed in to change notification settings

NASA-IMPACT/plotperfect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plotperfect

A lightweight matplotlib style library for producing publication-ready benchmark plots with consistent styling, colorblind-safe palettes, and zero configuration.

Installation

pip install git+https://github.com/NASA-IMPACT/plotperfect.git

For local development:

pip install -e ./plotperfect

Gallery

Grouped Bar
Single Bar
Line Plot
Scatter Plot
Stacked Bar
Horizontal Bar

Quick Start

import plotperfect as S

S.apply_style()
fig, ax = S.new_figure()

ax.bar(["A", "B", "C"], [3, 7, 5], color=S.COLOR_PRIMARY)
S.style_ax(ax, title="Demo", xlabel="Category", ylabel="Value")
S.save(fig, "demo.png")

See example.py for complete examples of every plot type shown in the gallery.

Style Guide

Color Palette

Ten colorblind-safe colors based on the seaborn "colorblind" palette. Access individual colors via S.COLORS["blue"] or use S.PALETTE (an ordered list) for multi-series plots.

Semantic aliases:

Alias Color Hex
COLOR_PRIMARY blue #2A79DB
COLOR_SECONDARY grey #949494
COLOR_TERTIARY green #029E73

Typography

All text is rendered in DM Sans (bundled with the package, auto-registered at import).

Element Size Weight
Title 14 pt Bold
Axis labels 14 pt Bold
Tick labels 12 pt Regular
Legend 14 pt Regular
Annotations 11 pt Regular

Layout

Property Default
Figure size 10 x 7 in
DPI 300
Bar width 0.35
Bar edge width 1.5

Colorblind Accessibility

Every plot should be distinguishable without color:

  • Bar plots — apply S.HATCHES (white hatch patterns) to differentiate series
  • Line / Scatter plots — apply S.MARKERS (distinct shapes per series)

Axes

style_ax() enforces a clean, consistent look:

  • Bold title and axis labels
  • Horizontal grid lines behind data
  • No vertical grid
  • Top and right spines removed
  • Bottom and left spines in #333333

Legend

add_legend() places the legend below the chart (bottom-center, outside the axes) in a single row with no title.

Annotations

Function Default format Notes
annotate_bars() {val:.2f} Pass total=N for percentage format
annotate_line() {val:.2f} Configurable offset and format

Both accept a custom fmt string with {val}, {pct}, and {total} placeholders.

API Reference

Function Description
apply_style() Set global matplotlib rcParams. Call once per script.
new_figure() Return a styled (fig, ax) pair.
style_ax() Apply grid, spines, labels, and limits to an axes.
annotate_bars() Add value labels above each bar.
annotate_line() Add value labels at each data point on a line.
add_legend() Place a bottom-center legend outside the axes.
save() Save the figure at 300 DPI with tight bounding box.

License

MIT

About

Opinionated matplotlib style kit with bundled DM Sans font, seaborn colorblind palette, and helpers for publication-ready benchmark plots.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages