plotnine
A Grammar of Graphics for Python
What it is and what it does
plotnine is a Python implementation of the grammar of graphics, modeled on R's ggplot2. It lets you build plots declaratively by mapping variables from a pandas DataFrame to visual properties (axes, colors, sizes, shapes) and then layering geometric objects, statistics, and themes using the `+` operator. Each layer is added incrementally, making it easy to build complex visualizations step by step while keeping simple plots simple.
The package depends on matplotlib for rendering, pandas for data handling, and scipy and statsmodels for statistical transformations. It works across macOS, Windows, and Unix, and supports current Python versions (3.10–3.13). The API mirrors ggplot2 closely, so R users can transfer their plotting intuition directly, and the documentation points to ggplot2 references where plotnine's coverage is incomplete.
Use it for:
- Build exploratory scatter plots with color-coded groups and trend lines, composing layers incrementally without rewriting the whole plot.
- Create publication-ready multi-panel plots using faceting to compare distributions or relationships across categorical subsets of data.
- Apply consistent themes and styling to a suite of plots by defining a theme once and reusing it across multiple visualizations.
- Perform statistical visualization (smoothing, confidence intervals, density estimation) by combining geoms with stats like stat_smooth.
- Prototype complex plots interactively in notebooks, adding and removing layers to refine the visualization without switching tools.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
plotnine implements a grammar of graphics for Python, letting you build plots by explicitly mapping dataframe variables to visual properties like position, color, and size, then composing them with operators.
Yes. plotnine is actively maintained, has no known vulnerabilities, installs with low friction, and offers a genuinely different (and for many users, more intuitive) approach to plotting than matplotlib's imperative style. It's well-suited for exploratory analysis and publication graphics if you prefer declarative composition. The MIT license is unrestricted. Install it if you work with pandas DataFrames and want to think about plots as layered grammars rather than imperative drawing commands.
Install
plotnine on PyPI
pip
pip install plotnineuv
uv add plotninepoetry
poetry add plotnineInstalling plotnine
Before you install
Low friction install with a pure-Python wheel. Active maintenance (last commit 2026-08-14) and a stable dependency set on matplotlib, pandas, numpy, scipy, statsmodels, and mizani. Supports Python 3.10 through 3.13.
License in practice
MIT license (permissive). You can use, modify, and distribute plotnine freely in commercial and private projects with minimal restrictions, provided you include the license notice.
Quickstart
pip install plotnine
from plotnine import ggplot, aes, geom_point
from plotnine.data import mtcars
(ggplot(mtcars, aes('wt', 'mpg'))
+ geom_point())
Verify before relying
- Whether image-based testing (comparing generated plots to baselines) is required for contributions or only for development.
- Performance characteristics with large datasets or complex multi-layer plots.
- Extent of API coverage compared to ggplot2 and which features may still be missing.
Package facts
| License | The MIT License (MIT) Copyright (c) 2022 Hassan Kibirige Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — matplotlib, pandas, mizani, numpy, scipy, statsmodels |
| Maintenance | actively maintained — 0 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,416,684/month — #2,629 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: plotnine-0.15.8-py3-none-any.whl
Tags
More Visualization packages
matplotlib creates static, animated, and…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
plotlyPlotly is an interactive, browser-based…
permissive · top 1,000 on PyPI
graphvizGenerates DOT language source code for graph…
permissive · top 1,000 on PyPI
streamlitStreamlit transforms Python scripts into…
permissive · top 1,000 on PyPI
leatherLeather is a lightweight Python charting…
permissive · top 1,000 on PyPI
ggplotggplot is a Python implementation of the…
permissive · top 15,000 on PyPI
mizaniMizani provides scales and transformations for…
permissive · top 5,000 on PyPI
plotillePlotille renders plots, scatter plots,…
permissive · top 15,000 on PyPI
plotextRenders plots directly in the terminal using…
permissive · top 5,000 on PyPI
bqscalesbqscales implements a grammar-of-graphics layer…
permissive · top 15,000 on PyPI
textual-plotextWraps the Plotext plotting library as a Textual…
permissive · top 15,000 on PyPI
UpSetPlotUpSetPlot generates visualizations of set…
permissive · top 15,000 on PyPI
bqplotbqplot is a 2-D interactive plotting library…
permissive · top 15,000 on PyPI
adjustTextAutomatically repositions text labels on…
permissive · top 5,000 on PyPI
altairAltair is a declarative Python library for…
permissive · top 1,000 on PyPI