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.1.tar.gz (67.3 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.1-py3-none-any.whl (84.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: djrhails_graphs-0.3.1.tar.gz
  • Upload date:
  • Size: 67.3 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.1.tar.gz
Algorithm Hash digest
SHA256 9b8d0418cb36dcb6ba4505e5df9812aff4e745fea09646078a90859d5fc12c94
MD5 c142bb451cc5fb49fb1c0bb689a2782b
BLAKE2b-256 db736bb7b933628e13622c6d5750f7715b654b8e9fd33934efcfdd32807365ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for djrhails_graphs-0.3.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: djrhails_graphs-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 84.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for djrhails_graphs-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b60eeb92d32243a9b2b159a196be75c586c038cdd07630f74a0705dc1b2001f0
MD5 4b3401c25ea59c8cfc7c119c4807de5e
BLAKE2b-256 63a5bc8c1ac7dd443f2fd502fb875f017682477e1033652509cf51be7e98bc8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for djrhails_graphs-0.3.1-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