plotnine
plotnine static visualization (ggplot2 syntax for Python). Geoms, aesthetics, scales, coordinates, facets, themes. Use for static publication-quality figures with grammar-of-graphics syntax. For interactive charts use plotly; for maps use geopandas.
Best use case
plotnine is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
plotnine static visualization (ggplot2 syntax for Python). Geoms, aesthetics, scales, coordinates, facets, themes. Use for static publication-quality figures with grammar-of-graphics syntax. For interactive charts use plotly; for maps use geopandas.
Teams using plotnine should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/plotnine/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How plotnine Compares
| Feature / Agent | plotnine | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
plotnine static visualization (ggplot2 syntax for Python). Geoms, aesthetics, scales, coordinates, facets, themes. Use for static publication-quality figures with grammar-of-graphics syntax. For interactive charts use plotly; for maps use geopandas.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Plotnine Skill
plotnine static visualization library for Python, implementing the grammar of graphics (ggplot2 syntax). Covers geoms (point, line, bar, histogram, boxplot, smooth), aesthetics, scales, coordinates, facets, and themes. Use when creating static publication-quality figures with ggplot2-style syntax, producing charts for print or reports, or working with an R ggplot2 background. Prefer over plotly when static output is needed.
Quick reference for creating data visualizations with plotnine, a Python implementation of the grammar of graphics (ggplot2).
## What is Plotnine?
plotnine is a data visualization library based on the **grammar of graphics**:
- **Declarative**: Describe what you want, not how to draw it
- **Layered**: Build plots by adding components with `+`
- **ggplot2 compatible**: Nearly identical syntax to R's ggplot2
- **Publication-ready**: Themes and customization for polished output
## How to Use This Skill
### Reference File Structure
| File | Purpose | When to Read |
|------|---------|--------------|
| `quickstart.md` | Installation, imports, basic syntax | Starting out |
| `geoms.md` | Geometric objects (points, lines, bars) | Choosing chart types |
| `aesthetics.md` | Mapping data to visual properties | Customizing appearance |
| `scales-coords.md` | Scales, coordinates, positions | Axis/color control |
| `facets-themes.md` | Multi-panel plots and styling | Layout and themes |
| `gotchas.md` | Common errors and best practices | Debugging |
## Quick Decision Trees
### "I need to create a plot"
```
What kind of plot?
├─ Scatter plot (geom_point) → ./references/geoms.md
├─ Line plot (geom_line) → ./references/geoms.md
├─ Bar chart (geom_bar, geom_col) → ./references/geoms.md
├─ Histogram (geom_histogram) → ./references/geoms.md
├─ Box plot (geom_boxplot) → ./references/geoms.md
└─ Other geoms → ./references/geoms.md
```
### "I need to customize appearance"
```
What to customize?
├─ Colors, sizes, shapes → ./references/aesthetics.md
├─ Axis limits/labels → ./references/scales-coords.md
├─ Color palettes → ./references/scales-coords.md
├─ Overall theme → ./references/facets-themes.md
├─ Title/labels → ./references/facets-themes.md
└─ Multiple panels (faceting) → ./references/facets-themes.md
```
### "Something isn't working"
```
Common issues?
├─ Plot not showing → ./references/quickstart.md
├─ Column not found → ./references/gotchas.md
├─ Color not applying → ./references/aesthetics.md
├─ Unexpected grouping → ./references/gotchas.md
└─ Syntax errors → ./references/gotchas.md
```
## File-First Execution in Research Workflows
**Important:** In data research pipelines (see `CLAUDE.md`), all visualizations are generated through **script files** in `scripts/stage8_analysis/`, not interactively. This ensures auditability and reproducibility.
**The pattern:**
1. Write plot code to `scripts/stage8_analysis/{step}_{plot-name}.py`
2. Execute via Bash with automatic output capture wrapper script
3. Validation results get automatically embedded in scripts as comments
4. If failed, create versioned copy for fixes
Closely read `agent_reference/SCRIPT_EXECUTION_REFERENCE.md` for the mandatory file-first execution protocol covering complete code file writing, output capture, and file versioning rules.
**See:**
- `agent_reference/WORKFLOW_PHASE4_ANALYSIS.md` — Stage 8 (Analysis & Visualization)
The examples below show plotnine syntax. In research workflows, wrap them in scripts following the file-first pattern.
---
## Quick Reference
### Basic Plot Pattern
```python
from plotnine import ggplot, aes, geom_point
(
ggplot(df, aes(x="col_x", y="col_y"))
+ geom_point()
)
```
### Essential Imports
```python
from plotnine import * # All components
from plotnine.data import mtcars # Built-in datasets
```
### Common Geoms
| Geom | Use Case |
|------|----------|
| `geom_point()` | Scatter plots |
| `geom_line()` | Line plots |
| `geom_bar()` | Count bars |
| `geom_col()` | Value bars |
| `geom_histogram()` | Distributions |
| `geom_boxplot()` | Box plots |
| `geom_smooth()` | Trend lines |
### Common Aesthetics
| Aesthetic | Controls |
|-----------|----------|
| `x`, `y` | Position |
| `color` | Point/line color |
| `fill` | Area fill color |
| `size` | Point/line size |
| `shape` | Point shape |
| `alpha` | Transparency |
### Saving Plots
```python
p = ggplot(df, aes("x", "y")) + geom_point()
p.save("plot.png", width=10, height=8, dpi=300)
```
## Topic Index
| Topic | Reference File |
|-------|---------------|
| Installation | `./references/quickstart.md` |
| Basic syntax | `./references/quickstart.md` |
| Chart types | `./references/geoms.md` |
| Data mapping | `./references/aesthetics.md` |
| Color/shape values | `./references/aesthetics.md` |
| Axis scales | `./references/scales-coords.md` |
| Color scales | `./references/scales-coords.md` |
| Coordinates | `./references/scales-coords.md` |
| Faceting | `./references/facets-themes.md` |
| Themes | `./references/facets-themes.md` |
| Labels/titles | `./references/facets-themes.md` |
| Common errors | `./references/gotchas.md` |
| Best practices | `./references/gotchas.md` |
## Citation
When this library is used as a primary analytical tool, include in the report's
Software & Tools references:
> Kibirige, H. et al. plotnine: Grammar of graphics for Python [Computer software]. https://plotnine.org/
**Cite when:** plotnine is the primary visualization library producing figures included in the report.
**Do not cite when:** Only used for quick exploratory plots not included in deliverables.Related Skills
svy
Complex survey analysis: strata/PSU/weights, variance estimation (Taylor, BRR, jackknife, bootstrap), survey GLM, domain analysis, calibration. Polars-native. Use for NHANES, CPS, ACS PUMS, BRFSS, DHS. Non-survey regression: statsmodels/pyfixest.
statsmodels
Statistical modeling: OLS/WLS/GLS, GLM (logit, probit, Poisson), time series (ARIMA, VAR), mixed effects, diagnostics. Formula API. Use for regressions without fixed effects, GLMs, or time series. For FE/DiD use pyfixest; panel/IV use linearmodels.
stata-python-translation
Stata-to-Python translation for data analysis. Maps Stata commands (reghdfe, xtreg, ivregress, margins, esttab, svy:) to Python (polars, pyfixest, statsmodels, svy). Use when user has Stata background or requests Stata-equivalent code comments.
skill-authoring
Guide for creating and auditing DAAF skills (SKILL.md). Covers frontmatter, metadata vocabulary, progressive disclosure, decision trees, reference files. Use when creating, reviewing, or debugging skill loading. For agent files, use agent-authoring.
science-communication
Translating technical findings for non-technical audiences. Narrative frameworks (Pyramid Principle, SCQA), plain-language translation, executive summaries, policy briefs, causal language. Use when presenting to stakeholders or reviewing deliverables
r-python-translation
R-to-Python translation for data analysis. Maps R packages (tidyverse, ggplot2, fixest, survey, sf, plm) to Python equivalents (polars, plotnine, pyfixest, svy, geopandas). Use when user has R background or requests R-equivalent code comments.
pyfixest
Fast high-dimensional fixed effects: OLS, Poisson, IV with multi-way FE; DiD (TWFE, did2s, Sun-Abraham); clustered SEs; etable/coefplot/iplot. Use for FE regressions or DiD. For panel RE/between use linearmodels; for GLM without FE use statsmodels.
polars
Polars DataFrame library for high-performance data manipulation. Lazy/eager execution, expressions, I/O (CSV, Parquet, JSON), aggregations, joins, string/datetime ops, pandas interop. Use for Polars DataFrames or reading/writing Parquet files.
plotly
Plotly interactive visualization. Express and Graph Objects: scatter, line, bar, heatmap, 3D, geographic charts; subplots; styling; export. Use when interactivity (hover/zoom) is needed. For static figures use plotnine; for GIS use geopandas.
marimo
Reactive Python notebook system. Cell reactivity, UI elements (sliders, dropdowns, tables), SQL cells, plotting, app deployment. Use when assembling Stage 9 notebooks, building data apps, or converting Jupyter to marimo .py format.
linearmodels
Panel data, IV/GMM, system regression. PanelOLS (FE/RE), BetweenOLS, Fama-MacBeth, IV2SLS/LIML/GMM, SUR, 3SLS, Driscoll-Kraay SEs. Use for RE/between, system estimation, or GMM. Complements pyfixest (FE + DiD) and statsmodels (GLM + time series).
geopandas
Spatial data: GeoDataFrames, spatial joins, CRS/projections, choropleth/interactive maps, spatial autocorrelation, PySAL. Use for geographic data, spatial files (Shapefile, GeoPackage, GeoParquet), or spatial stats. For charts without GIS use plotly.