explaingit

has2k1/plotnine

4,561PythonAudience · dataComplexity · 2/5Setup · easy

TLDR

plotnine is a Python charting library based on R's ggplot2 where you build charts by describing which data columns map to visual properties like position, color, and size, then layer additional elements on top.

Mindmap

mindmap
  root((plotnine))
    What it does
      Python charting
      Grammar of graphics
      ggplot2 port
    Chart Building
      Data to visual mapping
      Layered additions
      Facet panels
    Themes
      Professional minimalist
      xkcd hand-drawn
    Install
      pip
      conda
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Create a scatter plot with a smoothed trend line and split it into side-by-side panels by category in a few lines of Python

USE CASE 2

Build charts for reports or presentations and save them as image files using professional or xkcd hand-drawn themes

USE CASE 3

Port existing R ggplot2 visualizations to Python with a nearly identical API and syntax

Tech stack

Pythonpipconda

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

plotnine is a Python library for making charts and graphs. It is based on a popular R charting library called ggplot2, and brings the same approach to Python. The core idea is called a grammar of graphics: instead of calling a function that produces a specific chart type, you describe a chart by stating which columns in your data correspond to which visual properties, like position on the x-axis, position on the y-axis, color, or size. The library then assembles the chart from those descriptions. This approach means you build a chart piece by piece by adding layers. You might start with a scatter plot, then add a smoothed trend line on top of it, then split the result into separate side-by-side panels for each category in your data, then adjust the visual theme. Each of those additions is a separate line of code that gets combined with a plus sign. The README walks through exactly this sequence using a car dataset as an example, with images showing the result at each step. Theme options include a professional minimalist look and an intentionally hand-drawn look styled after the web comic xkcd. Plots can be saved as image files for use in reports or presentations. Installation is via pip or conda, the standard Python package managers. The base install is enough for most uses, with optional extras for testing, documentation generation, and development. A development version can also be installed directly from the repository. For users already familiar with R's ggplot2, the API is intentionally similar, and the ggplot2 documentation can serve as a reference when plotnine's own docs are incomplete. The project is open to contributions, particularly example plots that demonstrate useful techniques with real data.

Copy-paste prompts

Prompt 1
Using plotnine in Python, show me how to create a scatter plot of a dataset with a smoothed trend line and facet panels split by a category column
Prompt 2
How do I apply an xkcd hand-drawn theme to a plotnine chart?
Prompt 3
Show me how to layer multiple chart types in plotnine: start with a scatter plot, then add a line on top, then split into facets by group
Prompt 4
How do I save a plotnine chart as a PNG file at a specific size for use in a presentation?
Open on GitHub → Explain another repo

← has2k1 on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.