plotnine implements a ggplot2-style grammar of graphics in Python. You map dataframe columns to aesthetics and layer geoms and stats.
Overview
plotnine is a Python data visualization library based on the grammar of graphics, with an API modeled after ggplot2. You build plots by mapping variables in a dataframe to visual properties such as position, color, and size, then stacking geoms, statistics, facets, scales, and themes.
The grammar makes simple scatter or line charts short to write while still allowing multi-layer figures with smoothed trends, faceted panels, and customized legends. Defaults add sensible axes, colors, and labels from the data, and you can override scales, coordinates, and themes for publication-oriented output.
Documentation and examples walk from basic geoms through faceting and theme tuning. Because the interface mirrors ggplot2, gaps in plotnine docs can sometimes be cross-checked against ggplot2 references called out by the project.
plotnine installs from PyPI or a development checkout and is used inside notebooks, scripts, and reports wherever Python already runs. Image-based tests in the project compare rendered output against known-good baseline figures.
Key features
- ggplot2-like layered plot grammar
- Dataframe column to aesthetic mapping
- Geoms, stats, facets, and scales
- Automatic legends and color defaults
- Theme customization for output styling
- Faceting without manual panel loops
- Coordinate and axis limit control
- Baseline image regression tests
Use cases
- Exploratory plots in Python notebooks
- Publication figures from tidy tables
- Teaching grammar-of-graphics workflows
- Incremental plot refinement in scripts