Skip to content

DAAF-Contribution-Community/daaf / .claude/skills/plotnine

plotnine

Verified

plotnine 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).

FileKindSize
SKILL.mdskill md6.4 KB
references/aesthetics.mdmarkdown3.9 KB
references/facets-themes.mdmarkdown5.4 KB
references/geoms.mdmarkdown5.9 KB
references/gotchas.mdmarkdown6.4 KB
references/quickstart.mdmarkdown3.3 KB
references/scales-coords.mdmarkdown5.8 KB

references/facets-themes.md

View on GitHub
# Facets & Themes

## Faceting

Create multiple panels (small multiples) from data subsets.

### facet_wrap()

Wrap panels into rows/columns:

```python
# Single variable
facet_wrap("variable")

# Control layout
facet_wrap("variable", ncol=3)
facet_wrap("variable", nrow=2)

# Free scales
facet_wrap("variable", scales="free")
facet_wrap("variable", scales="free_x")
facet_wrap("variable", scales="free_y")
```

### facet_grid()

Grid layout with row and column variables:

```python
# Rows by one variable, columns by another
facet_grid("row_var ~ col_var")

# Only rows
facet_grid("row_var ~ .")

# Only columns
facet_grid(". ~ col_var")

# Free scales
facet_grid("row ~ col", scales="free")
```

### Facet Labels

```python
# Show variable name and value
facet_wrap("var", labeller=label_both)

# Custom labels
facet_wrap("var", labeller=labeller(var={"A": "Group A", "B": "Group B"}))
```

### Labeller Options

| Function | Result |
|----------|--------|
| `label_value` | Value only (default) |
| `label_both` | Variable: Value |
| `label_context` | Smart context |

## Labels & Titles

### labs()

Set multiple labels:

```python
labs(
    title="Main Title",
    subtitle="Subtitle",
    caption="Data source: ...",
    x="X Axis Label",
    y="Y Axis Label",
    color="Legend Title",
    fill="Fill Legend"
)
```

### Individual Functions

```python
ggtitle("Title")
xlab("X Label")
ylab("Y Label")
```

## Themes

### Premade Themes

| Theme | Description |
|-------|-------------|
| `theme_gray()` | Default gray background |
| `theme_bw()` | Black and white |
| `theme_minimal()` | Minimal, no background |
| `theme_classic()` | Classic, axes only |
| `theme_light()` | Light gray lines |
| `theme_dark()` | Dark background |
| `theme_void()` | Nothing (maps, etc.) |
| `theme_538()` | FiveThirtyEight style |
| `theme_tufte()` | Tufte minimal ink |
| `theme_xkcd()` | XKCD comic style |

```python
ggplot(df, aes("x", "y")) + geom_point() + theme_minimal()
```

### Theme Base Parameters

```python
theme_minimal(base_size=14, base_family="Arial")
```

## Custom Themes

### theme()

Modify individual elements:

```python
theme(
    axis_text=element_text(size=12),
    axis_title=element_text(size=14, weight="bold"),
    legend_position="bottom",
    panel_grid_major=element_line(color="gray", size=0.5),
    panel_background=element_rect(fill="white")
)
```

### Element Functions

| Function | For |
|----------|-----|
| `element_text()` | Text styling |
| `element_line()` | Lines and borders |
| `element_rect()` | Rectangles (backgrounds) |
| `element_blank()` | Remove element |

### element_text()

```python
element_text(
    size=12,
    color="black",
    family="Arial",
    weight="bold",      # normal, bold
    style="italic",     # normal, italic
    angle=45,
    hjust=0.5,          # horizontal alignment
    vjust=0.5           # vertical alignment
)
```

### element_line()

```python
element_line(
    color="gray",
    size=0.5,
    linetype="dashed"
)
```

### element_rect()

```python
element_rect(
    fill="white",
    color="black",
    size=1
)
```

### element_blank()

Remove an element:

```python
theme(panel_grid_minor=element_blank())
```

## Common Theme Modifications

### Legend Position

```python
theme(legend_position="bottom")     # bottom, top, left, right
theme(legend_position="none")       # remove legend
theme(legend_position=(0.8, 0.2))   # coordinates (0-1)
```

### Remove Grid Lines

```python
theme(
    panel_grid_major=element_blank(),
    panel_grid_minor=element_blank()
)
```

### Rotate Axis Labels

```python
theme(axis_text_x=element_text(angle=45, hjust=1))
```

### Transparent Background

```python
theme(
    panel_background=element_rect(fill="transparent"),
    plot_background=element_rect(fill="transparent")
)
```

### Figure Size

```python
theme(figure_size=(10, 6))  # width, height in inches
```

### DPI

```python
theme(dpi=300)
```

## Themeable Elements

### Axis

| Element | Description |
|---------|-------------|
| `axis_title` | Both axis titles |
| `axis_title_x` | X axis title |
| `axis_title_y` | Y axis title |
| `axis_text` | Both tick labels |
| `axis_text_x` | X tick labels |
| `axis_text_y` | Y tick labels |
| `axis_ticks` | Tick marks |
| `axis_line` | Axis lines |

### Panel

| Element | Description |
|---------|-------------|
| `panel_background` | Panel background |
| `panel_border` | Panel border |
| `panel_grid_major` | Major grid lines |
| `panel_grid_minor` | Minor grid lines |
| `panel_spacing` | Space between panels |

### Legend

| Element | Description |
|---------|-------------|
| `legend_position` | Position |
| `legend_title` | Legend title |
| `legend_text` | Legend labels |
| `legend_background` | Background |
| `legend_key` | Key background |

### Plot

| Element | Description |
|---------|-------------|
| `plot_title` | Main title |
| `plot_subtitle` | Subtitle |
| `plot_caption` | Caption |
| `plot_background` | Overall background |
| `plot_margin` | Margins |

### Strip (Facet Labels)

| Element | Description |
|---------|-------------|
| `strip_text` | Facet label text |
| `strip_text_x` | Top strip text |
| `strip_text_y` | Right strip text |
| `strip_background` | Strip background |

## Combining Themes

```python
(
    ggplot(df, aes("x", "y"))
    + geom_point()
    + theme_minimal()
    + theme(
        axis_text=element_text(size=12),
        legend_position="bottom"
    )
)
```

## Set Default Theme

```python
from plotnine import theme_set, theme_minimal

theme_set(theme_minimal())
```
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 implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
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 fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
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 alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall