Metadata-Version: 2.4
Name: workforce-plotting
Version: 0.2.0
Summary: Simple plotnine figures with Opportunity Insights styling.
Author: Corey Gelb-Bicknell
License-Expression: MIT
Project-URL: Repository, https://github.com/coreygb1/workforce-plotting
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: plotnine<0.16,>=0.15
Requires-Dist: pandas>=2.2
Requires-Dist: oi-tools>=0.11.7
Provides-Extra: polars
Requires-Dist: polars>=1; extra == "polars"
Requires-Dist: pyarrow>=14; extra == "polars"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: polars>=1; extra == "dev"
Requires-Dist: pyarrow>=14; extra == "dev"
Dynamic: license-file

# 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:

```bash
uv add 'workforce-plotting[polars]'
```

Or use pip:

```bash
pip install 'workforce-plotting[polars]'
```

For local development from this checkout:

```bash
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.

```python
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`.

```python
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.

```bash
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`.
