Plotnine

0.15.3 · active · verified Thu Apr 09

Plotnine is a Python package for data visualization, implementing a grammar of graphics inspired by R's ggplot2. It allows users to compose plots by explicitly mapping data variables to visual aesthetics, making it powerful for creating custom and complex visualizations incrementally. The library is actively maintained, with frequent releases. The current stable version is 0.15.3.

Warnings

Install

Imports

Quickstart

This example creates a scatter plot of bill length vs. bill depth, colored by penguin species, using the built-in `penguins` dataset. It demonstrates the fundamental `ggplot`, `aes`, and `geom_point` components of plotnine.

import pandas as pd
from plotnine import ggplot, aes, geom_point
from plotnine.data import penguins

# Create a basic scatter plot using the built-in penguins dataset
plot = (ggplot(penguins, aes(x='bill_length_mm', y='bill_depth_mm', color='species')) +
        geom_point())

# To display the plot (e.g., in a script or non-notebook environment)
# plot.show()

# In a Jupyter notebook or interactive environment, simply having the
# plot object as the last line will display it.
plot

view raw JSON →