Skip to main content

Matplotlib design system and flow diagram renderer for analytical publications

Project description

flowmpl

Matplotlib design system and flow diagram renderer for analytical publications.

Built for research notebooks that combine data visualization with process flow diagrams — the kind of work where you need both a consistent visual language across charts and clean auto-routed arrows between labeled boxes.

Install

pip install flowmpl           # core: matplotlib + numpy only
pip install flowmpl[charts]   # + pandas (annotated_series, stacked_bar, etc.)
pip install flowmpl[maps]     # + geopandas + requests (us_scatter_map)
pip install flowmpl[all]      # everything

Quick Start

from flowmpl import COLORS, FONTS, flow_diagram

fig = flow_diagram(
    nodes={
        "a": ("Announce", 1.0, 1.0, COLORS["accent"],    "#ffffff"),
        "b": ("Permit",   3.0, 1.0, COLORS["neutral"],   COLORS["text_dark"]),
        "c": ("Build",    5.0, 1.0, COLORS["positive"],  "#ffffff"),
    },
    edges=[
        {"src": "a", "dst": "b", "label": "12–18 mo"},
        {"src": "b", "dst": "c", "label": "24–36 mo"},
    ],
    title="From announcement to operation",
)
fig.savefig("pipeline.png", dpi=150, bbox_inches="tight")

Design System

flowmpl ships a complete design system extracted from a production research project:

Token Description
COLORS Semantic roles: accent, positive, negative, neutral, muted, reference, background, text_dark, text_light
CONTEXT SWD gray — use for non-focus elements in gray+accent charts
FONTS Font sizes for titles, labels, annotations, legends, captions
FIGSIZE Named figure sizes: standard, wide, tall, map
CATEGORICAL 8-color Paul Tol colorblind-safe palette
FUEL_COLORS Energy generation types: solar, wind, battery, gas_cc, gas_ct, nuclear, hydro, coal…
COMPANY_COLORS Hyperscaler tickers: MSFT, AMZN, GOOGL, META, NVDA, ORCL, AAPL, TSLA

Chart Functions

All functions return matplotlib.Figure objects.

from flowmpl import (
    annotated_series,       # time series with annotations + fill
    multi_panel,            # multi-subplot from a single DataFrame
    stacked_bar,            # stacked bar for categorical breakdowns
    waterfall_chart,        # cost allocation / flow breakdowns
    horizontal_bar_ranking, # ranked horizontal bars with highlights
)

Helpers

from flowmpl import (
    focus_colors,    # SWD gray+accent pattern: focus items colored, rest gray
    legend_below,    # place legend below axes (works with bbox_inches='tight')
    annotate_point,  # annotate a data point with arrow + text
    reference_line,  # labeled horizontal or vertical reference line
    chart_title,     # subtle left-aligned insight title (for standalone PNGs)
)

focus_colors() example

colors = focus_colors(
    ["MSFT", "AMZN", "GOOGL", "META"],
    focus="AMZN",
    color_map=COMPANY_COLORS,
)
# → ['#c0c0c0', '#ff9900', '#c0c0c0', '#c0c0c0']

Flow Diagram

flow_diagram() renders labeled boxes connected by auto-routed arrows. It handles:

  • Auto-routing: chooses straight or elbow connections based on source/destination geometry
  • Face overrides: explicit exit/entry keys bypass the heuristic for complex layouts
  • Auto-spacing: adjusts vertical spacing to prevent label overlap
  • Face spreading: distributes multiple edges from the same face to avoid overlaps

Node format

nodes = {
    "key": (label, cx, cy, fill_color, text_color),
}
  • cx, cy: center coordinates in abstract units (the renderer scales to fit)
  • Sizes auto-scaled; override with node_width / node_height params

Edge format

edges = [
    {"src": "a", "dst": "b"},                           # basic
    {"src": "a", "dst": "b", "label": "2 years"},       # with label
    {"src": "a", "dst": "b", "dashed": True},           # dashed line
    {"src": "a", "dst": "b", "color": "#888"},          # custom color
    {"src": "a", "dst": "b", "exit": "top",   "entry": "left"},  # face override
    {"src": "a", "dst": "b", "exit": "bottom", "entry": "left"}, # force exit face
]

Routing heuristic

The auto-router uses the vector between node centers:

Condition Route style
|vy| < 0.25 \* |vx| Near-horizontal — straight line
|vx| < 0.25 \* |vy| Near-vertical — straight line
|vy| < 0.75 \* |vx| Primarily-horizontal — exit top/bottom, enter side
else Primarily-vertical — exit side, enter top/bottom

Use explicit exit/entry overrides when the heuristic produces overlapping arrows from the same face (e.g., a root node with multiple connections at different angles).

T-layout example (face overrides)

fig = flow_diagram(
    nodes={
        "r": ("Root",   1.0, 1.5, COLORS["accent"],   "#ffffff"),
        "a": ("Top",    4.5, 3.0, COLORS["positive"], "#ffffff"),
        "m": ("Middle", 4.5, 1.5, COLORS["neutral"],  COLORS["text_dark"]),
        "b": ("Bottom", 4.5, 0.0, CONTEXT,            COLORS["text_dark"]),
    },
    edges=[
        {"src": "r", "dst": "a", "exit": "top",    "entry": "left"},
        {"src": "r", "dst": "m"},                           # straight, no override needed
        {"src": "r", "dst": "b", "exit": "bottom", "entry": "left"},
    ],
    title="Three destinations from one source",
)

Without the face overrides, all three arrows would exit from r's right face and overlap. With exit="top" and exit="bottom", each arrow leaves from a different face.

Map

from flowmpl import us_scatter_map
import matplotlib.patches as mpatches

fig = us_scatter_map(
    lats=[37.7, 40.7, 41.8],
    lons=[-122.4, -74.0, -87.6],
    colors=["#e74c3c", "#3498db", "#2ecc71"],
    sizes=[100, 150, 80],
    title="Three cities",
    legend_handles=[
        mpatches.Patch(color="#e74c3c", label="San Francisco"),
        mpatches.Patch(color="#3498db", label="New York"),
        mpatches.Patch(color="#2ecc71", label="Chicago"),
    ],
)

State boundary shapefiles are downloaded from the US Census Bureau on first use and cached in the package directory.

License

MIT

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

flowmpl-0.2.0.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

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

flowmpl-0.2.0-py3-none-any.whl (210.6 kB view details)

Uploaded Python 3

File details

Details for the file flowmpl-0.2.0.tar.gz.

File metadata

  • Download URL: flowmpl-0.2.0.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for flowmpl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4176d0c6f42d22dc05ab02b7c9e375f36311be0b54bd27642fcffaf019d598c9
MD5 8eddabedb9f8ea6a0afb1c5b3e0d7c54
BLAKE2b-256 87d7bbe78a83669eab528c7df947173f1b4fea2dab51841b313cf688a378e818

See more details on using hashes here.

File details

Details for the file flowmpl-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: flowmpl-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 210.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for flowmpl-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f7917f3f81b0ca2d7fefa160dba72f11a3337dd7f9015dc6c1dc74bde7ad5c2
MD5 345c914212fb350ba4d6753c4ebed990
BLAKE2b-256 8eb16fe1d60133ac134fa976d07984552ecad5b69302ca24088c6e6acedcea78

See more details on using hashes here.

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