Skip to main content

Economist-style chart theme for matplotlib/seaborn

Project description

graphs

Economist-style chart theme for matplotlib and seaborn — global theme, title-stack finaliser, direct line labels, CI bands, horizontal bars, and dumbbell charts. Uses IBM Plex Sans typography and a curated 8-colour palette.

Version: 0.3.1

Install

pip install djrhails-graphs

PyPI distribution is djrhails-graphs because the bare name graphs is taken. The import package is graphs.

Quick start

import matplotlib.pyplot as plt
from graphs import ci_fill, finalize, label_lines, set_theme

set_theme()

fig, ax = plt.subplots()
fig.subplots_adjust(top=0.68, bottom=0.14, left=0.06, right=0.88)

ax.plot(x, y, label="Series A")
label_lines(ax)
finalize(
    ax,
    title="Bold chart title",
    descriptor="Country, metric, unit",
    source="Source: Organisation",
)

See examples/ for runnable scripts:

  • line_chart.py — multi-series line with CI bands + direct labels
  • faceted_chart.py — three-panel faceted layout with panel labels
  • bar_chart.py — horizontal bar with max-value highlight
  • dumbbell_chart.py — before/after comparison with legend

Public API

Function Purpose
set_theme() Apply global rcParams (figure, axes, ticks, fonts, palette)
finalize(ax, title, descriptor, source, *, y_axis_right, title_x, y_start, autoscale_y) Title stack, red rule, source line, y-axis tidy-up
label_lines(ax, ...) Direct end-of-line labels with collision avoidance
smart_legend(ax, ...) Pick the emptiest corner of the axes
ci_fill(ax, x, y_lo, y_hi, *, color) Confidence-interval band
bar_h(ax, categories, values, *, highlight_max) Horizontal bar chart
dumbbell(ax, categories, start, end, ...) Dot-and-line before/after chart
panel_label(ax, label) Bold panel sub-heading for facets

Palette

from graphs import colors, C_BG, C_RED, C_SPINE, C_GRID, C_LABEL, C_TEXT, C_CI

Sequence colors (red primary, blue, teal, green, yellow, mauve, slate, coral).

Typography

IBM Plex Sans is loaded automatically. If already registered in matplotlib's font manager, no download occurs. Otherwise TTFs are fetched from github.com/IBM/plex on first use and cached inside the installed package.

Fallback chain: IBM Plex Sans → Verdana → Arial → DejaVu Sans.

Development

Hot reload:

uv run graphs-watch

Watches graphs/ and examples/ for .py changes and re-renders the affected examples + comparisons.

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djrhails_graphs-0.3.2.tar.gz (70.2 kB view details)

Uploaded Source

Built Distribution

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

djrhails_graphs-0.3.2-py3-none-any.whl (87.4 kB view details)

Uploaded Python 3

File details

Details for the file djrhails_graphs-0.3.2.tar.gz.

File metadata

  • Download URL: djrhails_graphs-0.3.2.tar.gz
  • Upload date:
  • Size: 70.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for djrhails_graphs-0.3.2.tar.gz
Algorithm Hash digest
SHA256 d91feed3c261b3a01607b7d487382b7859a16b508acf3d18e511a04bab0b873f
MD5 5b7885e8dba3bb357b1d09793b694358
BLAKE2b-256 a1856b42b99a8f556d558ba195daa019c0b1b1479d5c9997fa13590637bddd28

See more details on using hashes here.

Provenance

The following attestation bundles were made for djrhails_graphs-0.3.2.tar.gz:

Publisher: release.yml on DJRHails/graphs

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

File details

Details for the file djrhails_graphs-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for djrhails_graphs-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 112b30a98d7e2e349f68cd34ffc1b7b5341164e55e5395f48043b6f69e95f0d7
MD5 5a8f7564e489ccf57bd533c3d0d89d22
BLAKE2b-256 7de5a65bf77ae8f7a45ca66065838f94c605c34efd90a6020f129dca068e6d2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for djrhails_graphs-0.3.2-py3-none-any.whl:

Publisher: release.yml on DJRHails/graphs

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page