Seaborn

From G1Joshi/Agent-Skills · View interactive version

Seaborn is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Seaborn statistical data visualization assistance covering statistical charts, categorical plots, heatmap matrices, and themes. Use when creating insightful statistical graphics and exploratory data analysis plots.

How to use this skill

Skill file

Seaborn

Seaborn is a high-level wrapper around Matplotlib. It makes statistical plots (violins, heatmaps, pairs) easy.

When to Use

Quick Start

import seaborn as sns
import matplotlib.pyplot as plt

# Load sample dataset and plot regression with confidence interval
tips = sns.load_dataset("tips")

plt.figure(figsize=(8, 5))
sns.set_theme(style="whitegrid")
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time", size="size")
plt.title("Tip Amount vs Total Bill by Dining Time")
plt.show()

Core Concepts

Modern Seaborn Objects Interface (sns.objects)

Grammar of graphics data visualization:

import seaborn.objects as so
import seaborn as sns
import matplotlib.pyplot as plt

# Load sample dataset
penguins = sns.load_dataset("penguins").dropna()

# Declarative grammar of graphics plot
plot = (
    so.Plot(penguins, x="bill_length_mm", y="bill_depth_mm", color="species", pointsize="body_mass_g")
    .add(so.Dots(alpha=0.7))
    .add(so.Line(), so.PolyFit(order=1))
    .label(
        title="Penguin Bill Dimensions & Linear Fits",
        x="Bill Length (mm)",
        y="Bill Depth (mm)",
        color="Species"
    )
    .theme({"axes.grid": True})
)

fig = plt.figure(figsize=(9, 5))
plot.on(fig).save("seaborn_objects_plot.png")

Statistical Distributions & Faceted Grids

Visualizing density and distributions across categories:

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid", palette="muted")
tips = sns.load_dataset("tips")

# Multi-panel faceted distribution
g = sns.displot(
    data=tips,
    x="total_bill",
    hue="time",
    col="day",
    kind="kde",
    fill=True,
    common_norm=False,
    palette="crest",
    height=3.5,
    aspect=0.8
)

g.set_axis_labels("Total Bill ($)", "Density")
g.savefig("tips_kde_faceted.png", bbox_inches="tight")
plt.close()

Categorical Box and Violin Comparisons

Comparing distributions across discrete classes:

fig, ax = plt.subplots(figsize=(8, 5))

sns.violinplot(
    data=tips,
    x="day",
    y="total_bill",
    hue="sex",
    split=True,
    inner="quart",
    palette={"Male": "#3b82f6", "Female": "#ec4899"},
    ax=ax
)

ax.set_title("Total Bill Distribution by Day & Gender")
plt.savefig("violin_comparison.png", bbox_inches="tight")
plt.close(fig)

Common Patterns

Correlation Heatmap with Masked Triangle

Problem: Large correlation heatmaps are visually redundant and cluttered when showing both upper and lower triangles.

Solution:

Mask upper triangle using NumPy:

import numpy as np

corr = df.select_dtypes(include=np.number).corr()
mask = np.triu(np.ones_like(corr, dtype=bool))

plt.figure(figsize=(10, 8))
sns.heatmap(corr, mask=mask, cmap="vlag", vmax=1.0, vmin=-1.0,
            annot=True, fmt=".2f", square=True, linewidths=.5)
plt.title("Feature Correlation Matrix")
plt.show()

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :--------------------------------------------------------- | :----------------------------------------------- | :------------------------------------------------------------- |

| TypeError: Object of type '...' is not JSON serializable | Passing non-numeric columns to heatmap(). | Filter numeric columns: df.select_dtypes(include=np.number). |

| Seaborn plot showing tiny unreadable fonts | Default scaling mismatch with high-DPI displays. | Set context scaling: sns.set_context("talk") or "poster". |

| AttributeError: module 'seaborn' has no attribute '...' | Outdated Seaborn version installed. | Upgrade Seaborn to 0.13+: pip install --upgrade seaborn. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.