Skip to main content

workforce-plotting

Five small plotnine functions with a shared Opportunity Insights style. Supply prepared estimates and confidence bounds; the functions only draw them. Every function returns a plotnine.ggplot that you can edit with ordinary layers.

Install

Python 3.12 or newer is required (matching oi-tools). For a Polars workflow:

uv add 'workforce-plotting[polars]'

Or use pip:

pip install 'workforce-plotting[polars]'

For local development from this checkout:

pip install -e '.[dev]'

For Polars input, install the polars extra, which also supplies the Arrow conversion dependency. Pandas input needs no extra.

Functions

Function Use
plot_lines(data, x=..., y=..., series=...) Event studies, trajectories, cohort trends, model complexity
plot_validation(data, x=..., y=...) RCT versus digital-twin estimates with an identity line
plot_bars(data, x=..., y=..., series=...) Already-calculated values by category
plot_scatter(data, x=..., y=..., fitted=...) Points with an optional precomputed fitted line
plot_intervals(data, x=..., y=..., lower=..., upper=...) Estimates and supplied confidence intervals
theme_workforce() Shared white background, gray axes, sans-serif type, no grid

plot_lines accepts lower and upper columns and points=False. plot_validation accepts x_lower, x_upper, y_lower, y_upper, gaps="horizontal" or "vertical", and a common (min, max) pair of limits. The identity line has slope one in data units; the panel follows the figure's aspect ratio. Other functions accept series for discrete groups. Use ordered categorical columns to control color/legend order. Colors are teal, orange, navy, purple, blue, red, and dark green from the public oi_tools.figures.OIColors API. For a different mapping, add a plotnine manual color or fill scale.

import plotnine as pn
from workforce_plotting import plot_lines

p = plot_lines(df, x="year", y="earnings", series="group")
p += pn.labs(x="Years since enrollment", y="Mean annual earnings")
p.save("earnings.svg")

Dataframes should be tidy: one row per plotted point, with separate columns for x, y, and an optional series. Lines connect points in x order within each series. Include a row with a missing y where a line should break; simply omitting a row connects the remaining observations. Fitted lines use the same column names as the scatter data. No smoothing, RMSE calculation, confidence-interval estimation, or automatic saving happens inside the plotting functions.

Add pn.coord_flip() for horizontal bars/intervals; use ordinary plotnine scales for dollars, percentages, limits, or log axes. Fonts, dimensions, and text size use Lucida Sans when installed and DejaVu Sans otherwise. They can be overridden with theme_workforce(base_family=..., base_size=..., width=..., height=...). Titles, logos, notes, and paper-specific annotations belong in the example/caller.

Styling your own plots

Use the theme and colors without using the plot constructors. WFColors is an alias of oi_tools.figures.OIColors, and theme_workforce builds on theme_oi. The oi-tools dependency remains; you only need workforce imports in your code. All plotting functions and styling live together in workforce_plotting/figures.py.

import polars as pl
import plotnine as pn
from workforce_plotting import theme_workforce, WFColors

df = pl.DataFrame({"year": [2020, 2021, 2022], "earnings": [20000, 23000, 25000]})
p = (
    pn.ggplot(df.to_pandas(), pn.aes(x="year", y="earnings"))
    + pn.geom_line(color=WFColors.TEAL)
    + pn.geom_point(color=WFColors.TEAL)
    + theme_workforce()
    + pn.labs(x="Year", y="Annual earnings")
)
p.save("earnings.svg")

Plot constructors accept Polars directly. When building a plotnine plot yourself, the explicit conversion above works with the supported plotnine version.

Editable examples

examples/paper_examples.py contains synthetic recipes for the paper/deck plot families. These are invented values, not research results.

python examples/paper_examples.py outputs/examples
pytest

Changes from 0.1

This is a fresh API. The old Matplotlib functions, plotting dataclasses, curve fitting machinery, and aipw_analysis compatibility package have been removed. Plot creation and saving are now separate. The public API consists of the five plot functions, theme_workforce, and WFColors.

Metadata

Release files for workforce-plotting 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for workforce-plotting 0.2.0
File Size Uploaded Provenance Actions
workforce_plotting-0.2.0.tar.gz 11.1 kB With provenance Details for workforce_plotting-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for workforce-plotting 0.2.0
File Interpreter ABI Platform Actions
workforce_plotting-0.2.0-py3-none-any.whl Python 3 none any Details for workforce_plotting-0.2.0-py3-none-any.whl

Total release size: 18.1 kB

Release files / workforce_plotting-0.2.0.tar.gz

Download URL workforce_plotting-0.2.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f31af149e02a655d22133fc57392d6d491ecbe67d87e2e189789d5a2c6f3d714
BLAKE2b-256 checksum
How to use checksums
3b93eb974e86b65f79990bea6df0d77b6a140afea06c80bf6dd00347a7392446
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / workforce_plotting-0.2.0-py3-none-any.whl

Download URL workforce_plotting-0.2.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a071304cb909eeb4df2e1f7cf3fbdf262d8db621ea6a48153aaa6a169027e691
BLAKE2b-256 checksum
How to use checksums
b1dda5ce03c8575f7e19b5d4c753b4aa5dcfa387ffbd1a592d2ce9b67e593161
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for workforce-plotting 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for workforce_plotting-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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