DAAF-Contribution-Community/daaf / .claude/skills/plotnine
plotnine
Verifiedplotnine 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. R equivalent: ggplot2 (use when execution language is R).
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.4 KB |
| references/aesthetics.md | markdown | 3.9 KB |
| references/facets-themes.md | markdown | 5.4 KB |
| references/geoms.md | markdown | 5.9 KB |
| references/gotchas.md | markdown | 6.4 KB |
| references/quickstart.md | markdown | 3.3 KB |
| references/scales-coords.md | markdown | 5.8 KB |
references/quickstart.md
View on GitHub# Quickstart
## Installation
No installation needed in DAAF: `plotnine` (0.15.3) is pre-installed in the
container. Runtime installs are blocked in DAAF (`pip install`/`uv add` are
refused both at the command line and inside executed scripts — see CLAUDE.md
§ Runtime Package Installation). If a package beyond the pinned install is needed,
escalate to the user to add it to the Dockerfile (user additions block near the
end) and rebuild.
## Basic Imports
```python
# Import everything (common approach)
from plotnine import *
# Or import specific components
from plotnine import ggplot, aes, geom_point, geom_line, theme_minimal
```
## Built-in Datasets
```python
from plotnine.data import mtcars, diamonds, mpg, economics, faithful
```
## Basic Plot Anatomy
Every plot follows this pattern:
```python
(
ggplot(data, aes(x="column_x", y="column_y")) # Data + aesthetics
+ geom_point() # Geometry layer
)
```
### Key Components
| Component | Purpose |
|-----------|---------|
| `ggplot()` | Initialize plot with data |
| `aes()` | Map columns to visual properties |
| `geom_*()` | Define how to represent data |
| `+` | Add layers/components |
## Minimal Example
```python
from plotnine import ggplot, aes, geom_point
from plotnine.data import mtcars
(
ggplot(mtcars, aes(x="wt", y="mpg"))
+ geom_point()
)
```
## Adding Layers
Layers are added with `+`:
```python
(
ggplot(mtcars, aes("wt", "mpg"))
+ geom_point()
+ geom_smooth(method="lm")
)
```
## Multi-line Syntax
Use parentheses to span multiple lines:
```python
p = (
ggplot(df, aes("x", "y"))
+ geom_point()
+ theme_minimal()
)
```
## Displaying Plots
### In Jupyter/IPython
The plot displays automatically as the last expression:
```python
ggplot(df, aes("x", "y")) + geom_point()
```
### In Scripts
Assign to variable and call `.draw()`:
```python
p = ggplot(df, aes("x", "y")) + geom_point()
p.draw()
```
## Saving Plots
```python
p = ggplot(df, aes("x", "y")) + geom_point()
# Basic save
p.save("plot.png")
# With options
p.save("plot.png", width=10, height=8, dpi=300)
# Different formats
p.save("plot.pdf")
p.save("plot.svg")
```
### Save Parameters
| Parameter | Description |
|-----------|-------------|
| `filename` | Output path |
| `width` | Width in inches |
| `height` | Height in inches |
| `dpi` | Resolution (default 100) |
| `format` | Override file extension |
## DataFrame Requirements
plotnine works with:
- **Pandas DataFrame** (primary)
- **Polars DataFrame** (supported)
Column names are passed as **strings**:
```python
# Correct
aes(x="column_name", y="other_column")
# Wrong
aes(x=column_name, y=other_column)
```
## Quick Examples
### Scatter with Color
```python
(
ggplot(mtcars, aes("wt", "mpg", color="factor(cyl)"))
+ geom_point()
)
```
### Line Plot
```python
(
ggplot(economics, aes("date", "unemploy"))
+ geom_line()
)
```
### Bar Chart
```python
(
ggplot(mtcars, aes(x="factor(cyl)"))
+ geom_bar()
)
```
### Histogram
```python
(
ggplot(diamonds, aes(x="price"))
+ geom_histogram(bins=30)
)
```
## Next Steps
- [Geoms](./geoms.md) - Chart types
- [Aesthetics](./aesthetics.md) - Visual mappings
- [Scales & Coords](./scales-coords.md) - Axis control
- [Facets & Themes](./facets-themes.md) - Layout and styling
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |