Skill Tracer
Skills › Scientific Agent Skills › seaborn › plotting_functions.md

plotting_functions.md

180 lines · skills/seaborn/references/plotting_functions.md at 5f2bc03

Open on GitHub
1# Plotting Functions by Category
2
3Relational, distribution, categorical, regression, and matrix plots: which function to
4reach for, its key parameters, and worked examples.
5

Plotting Functions by Category

Relational, distribution, categorical, regression, and matrix plots: which function to reach for, its key parameters, and worked examples.

Raw lines 1 to 5
6## Plotting Functions by Category
7

Plotting Functions by Category

Raw lines 6 to 7
8### Relational Plots (Relationships Between Variables)
9
10**Use for:** Exploring how two or more variables relate to each other
12- `scatterplot()` - Display individual observations as points
13- `lineplot()` - Show trends and changes (automatically aggregates and computes CI)
14- `relplot()` - Figure-level interface with automatic faceting
16**Key parameters:**
17- `x`, `y` - Primary variables
18- `hue` - Color encoding for additional categorical/continuous variable
19- `size` - Point/line size encoding
20- `style` - Marker/line style encoding
21- `col`, `row` - Facet into multiple subplots (figure-level only)
23```python
24# Scatter with multiple semantic mappings
25sns.scatterplot(data=df, x='total_bill', y='tip',
26 hue='time', size='size', style='sex')
28# Line plot with confidence intervals
29sns.lineplot(data=timeseries, x='date', y='value', hue='category')
31# Faceted relational plot
32sns.relplot(data=df, x='total_bill', y='tip',
33 col='time', row='sex', hue='smoker', kind='scatter')
34```

Relational Plots (Relationships Between Variables)

Use for: Exploring how two or more variables relate to each other

  • scatterplot() - Display individual observations as points
  • lineplot() - Show trends and changes (automatically aggregates and computes CI)
  • relplot() - Figure-level interface with automatic faceting

Key parameters:

  • x, y - Primary variables
  • hue - Color encoding for additional categorical/continuous variable
  • size - Point/line size encoding
  • style - Marker/line style encoding
  • col, row - Facet into multiple subplots (figure-level only)
# Scatter with multiple semantic mappings
sns.scatterplot(data=df, x='total_bill', y='tip',
                hue='time', size='size', style='sex')

# Line plot with confidence intervals
sns.lineplot(data=timeseries, x='date', y='value', hue='category')

# Faceted relational plot
sns.relplot(data=df, x='total_bill', y='tip',
            col='time', row='sex', hue='smoker', kind='scatter')
Raw lines 8 to 35
36### Distribution Plots (Single and Bivariate Distributions)
38**Use for:** Understanding data spread, shape, and probability density
40- `histplot()` - Bar-based frequency distributions with flexible binning
41- `kdeplot()` - Smooth density estimates using Gaussian kernels
42- `ecdfplot()` - Empirical cumulative distribution (no parameters to tune)
43- `rugplot()` - Individual observation tick marks
44- `displot()` - Figure-level interface for univariate and bivariate distributions
45- `jointplot()` - Bivariate plot with marginal distributions
46- `pairplot()` - Matrix of pairwise relationships across dataset
48**Key parameters:**
49- `x`, `y` - Variables (y optional for univariate)
50- `hue` - Separate distributions by category
51- `stat` - Normalization: "count", "frequency", "probability", "density"
52- `bins` / `binwidth` - Histogram binning control
53- `bw_adjust` - KDE bandwidth multiplier (higher = smoother)
54- `fill` - Fill area under curve
55- `multiple` - How to handle hue: "layer", "stack", "dodge", "fill"
57```python
58# Histogram with density normalization
59sns.histplot(data=df, x='total_bill', hue='time',
60 stat='density', multiple='stack')
62# Bivariate KDE with contours
63sns.kdeplot(data=df, x='total_bill', y='tip',
64 fill=True, levels=5, thresh=0.1)
66# Joint plot with marginals
67sns.jointplot(data=df, x='total_bill', y='tip',
68 kind='scatter', hue='time')
70# Pairwise relationships
71sns.pairplot(data=df, hue='species', corner=True)
72```

Distribution Plots (Single and Bivariate Distributions)

Use for: Understanding data spread, shape, and probability density

  • histplot() - Bar-based frequency distributions with flexible binning
  • kdeplot() - Smooth density estimates using Gaussian kernels
  • ecdfplot() - Empirical cumulative distribution (no parameters to tune)
  • rugplot() - Individual observation tick marks
  • displot() - Figure-level interface for univariate and bivariate distributions
  • jointplot() - Bivariate plot with marginal distributions
  • pairplot() - Matrix of pairwise relationships across dataset

Key parameters:

  • x, y - Variables (y optional for univariate)
  • hue - Separate distributions by category
  • stat - Normalization: "count", "frequency", "probability", "density"
  • bins / binwidth - Histogram binning control
  • bw_adjust - KDE bandwidth multiplier (higher = smoother)
  • fill - Fill area under curve
  • multiple - How to handle hue: "layer", "stack", "dodge", "fill"
# Histogram with density normalization
sns.histplot(data=df, x='total_bill', hue='time',
             stat='density', multiple='stack')

# Bivariate KDE with contours
sns.kdeplot(data=df, x='total_bill', y='tip',
            fill=True, levels=5, thresh=0.1)

# Joint plot with marginals
sns.jointplot(data=df, x='total_bill', y='tip',
              kind='scatter', hue='time')

# Pairwise relationships
sns.pairplot(data=df, hue='species', corner=True)
Raw lines 36 to 73
74### Categorical Plots (Comparisons Across Categories)
76**Use for:** Comparing distributions or statistics across discrete categories
78**Categorical scatterplots:**
79- `stripplot()` - Points with jitter to show all observations
80- `swarmplot()` - Non-overlapping points (beeswarm algorithm)
82**Distribution comparisons:**
83- `boxplot()` - Quartiles and outliers
84- `violinplot()` - KDE + quartile information
85- `boxenplot()` - Enhanced boxplot for larger datasets
87**Statistical estimates:**
88- `barplot()` - Mean/aggregate with confidence intervals
89- `pointplot()` - Point estimates with connecting lines
90- `countplot()` - Count of observations per category
92**Figure-level:**
93- `catplot()` - Faceted categorical plots (set `kind` parameter)
95**Key parameters:**
96- `x`, `y` - Variables (one typically categorical)
97- `hue` - Additional categorical grouping
98- `order`, `hue_order` - Control category ordering
99- `native_scale` - Preserve numeric/datetime scale on the categorical axis
100- `log_scale` - Apply log scaling without dropping down to matplotlib
101- `formatter` - Format categorical values; affects both grouping and tick labels
102- `dodge` - Separate hue levels; `gap` applies to box/violin/boxen/bar/count, not every categorical function
103- `orient` - "x"/"y" or "v"/"h" to specify the categorical axis
104- `legend` - True/False or "auto", "brief", "full"
105- `kind` - Plot type for catplot: "strip", "swarm", "box", "violin", "boxen", "bar", "point", "count"
107```python
108# Swarm plot showing all points
109sns.swarmplot(data=df, x='day', y='total_bill', hue='sex')
111# Violin plot with split for comparison
112sns.violinplot(data=df, x='day', y='total_bill',
113 hue='sex', split=True)
115# Bar plot with error bars
116sns.barplot(data=df, x='day', y='total_bill',
117 hue='sex', estimator='mean', errorbar=('ci', 95))
119# Faceted categorical plot
120sns.catplot(data=df, x='day', y='total_bill',
121 col='time', kind='box')
122```

Categorical Plots (Comparisons Across Categories)

Use for: Comparing distributions or statistics across discrete categories

Categorical scatterplots:

  • stripplot() - Points with jitter to show all observations
  • swarmplot() - Non-overlapping points (beeswarm algorithm)

Distribution comparisons:

  • boxplot() - Quartiles and outliers
  • violinplot() - KDE + quartile information
  • boxenplot() - Enhanced boxplot for larger datasets

Statistical estimates:

  • barplot() - Mean/aggregate with confidence intervals
  • pointplot() - Point estimates with connecting lines
  • countplot() - Count of observations per category

Figure-level:

  • catplot() - Faceted categorical plots (set kind parameter)

Key parameters:

  • x, y - Variables (one typically categorical)
  • hue - Additional categorical grouping
  • order, hue_order - Control category ordering
  • native_scale - Preserve numeric/datetime scale on the categorical axis
  • log_scale - Apply log scaling without dropping down to matplotlib
  • formatter - Format categorical values; affects both grouping and tick labels
  • dodge - Separate hue levels; gap applies to box/violin/boxen/bar/count, not every categorical function
  • orient - "x"/"y" or "v"/"h" to specify the categorical axis
  • legend - True/False or "auto", "brief", "full"
  • kind - Plot type for catplot: "strip", "swarm", "box", "violin", "boxen", "bar", "point", "count"
# Swarm plot showing all points
sns.swarmplot(data=df, x='day', y='total_bill', hue='sex')

# Violin plot with split for comparison
sns.violinplot(data=df, x='day', y='total_bill',
               hue='sex', split=True)

# Bar plot with error bars
sns.barplot(data=df, x='day', y='total_bill',
            hue='sex', estimator='mean', errorbar=('ci', 95))

# Faceted categorical plot
sns.catplot(data=df, x='day', y='total_bill',
            col='time', kind='box')
Raw lines 74 to 123
124### Regression Plots (Linear Relationships)
126**Use for:** Visualizing linear regressions and residuals
128- `regplot()` - Axes-level regression plot with scatter + fit line
129- `lmplot()` - Figure-level with faceting support
130- `residplot()` - Residual plot for assessing model fit
132**Key parameters:**
133- `x`, `y` - Variables to regress
134- `order` - Polynomial regression order
135- `logistic` - Fit logistic regression
136- `robust` - Use robust regression (less sensitive to outliers)
137- `ci` - Confidence interval width (default 95)
138- `scatter_kws`, `line_kws` - Customize scatter and line properties
140```python
141# Simple linear regression
142sns.regplot(data=df, x='total_bill', y='tip')
144# Polynomial regression with faceting
145sns.lmplot(data=df, x='total_bill', y='tip',
146 col='time', order=2, ci=95)
148# Check residuals
149sns.residplot(data=df, x='total_bill', y='tip')
150```

Regression Plots (Linear Relationships)

Use for: Visualizing linear regressions and residuals

  • regplot() - Axes-level regression plot with scatter + fit line
  • lmplot() - Figure-level with faceting support
  • residplot() - Residual plot for assessing model fit

Key parameters:

  • x, y - Variables to regress
  • order - Polynomial regression order
  • logistic - Fit logistic regression
  • robust - Use robust regression (less sensitive to outliers)
  • ci - Confidence interval width (default 95)
  • scatter_kws, line_kws - Customize scatter and line properties
# Simple linear regression
sns.regplot(data=df, x='total_bill', y='tip')

# Polynomial regression with faceting
sns.lmplot(data=df, x='total_bill', y='tip',
           col='time', order=2, ci=95)

# Check residuals
sns.residplot(data=df, x='total_bill', y='tip')
Raw lines 124 to 151
152### Matrix Plots (Rectangular Data)
154**Use for:** Visualizing matrices, correlations, and grid-structured data
156- `heatmap()` - Color-encoded matrix with annotations
157- `clustermap()` - Hierarchically-clustered heatmap
159**Key parameters:**
160- `data` - 2D rectangular dataset (DataFrame or array)
161- `annot` - Display values in cells
162- `fmt` - Format string for annotations (e.g., ".2f")
163- `cmap` - Colormap name
164- `center` - Value at colormap center (for diverging colormaps)
165- `vmin`, `vmax` - Color scale limits
166- `square` - Force square cells
167- `linewidths` - Gap between cells
169```python
170# Correlation heatmap
171corr = df.select_dtypes(include='number').corr()
172sns.heatmap(corr, annot=True, fmt='.2f',
173 cmap='coolwarm', center=0, square=True)
175# Clustered heatmap
176sns.clustermap(data, cmap='viridis',
177 standard_scale=1, figsize=(10, 10))
178```
180These are selected parameters, not a union accepted by every function. Check [function_reference.md](function_reference.md) for estimator, missing-data, regression, and clustering constraints. APIs reviewed against the [stable API index](https://seaborn.pydata.org/api.html), 2026-10-01.

Matrix Plots (Rectangular Data)

Use for: Visualizing matrices, correlations, and grid-structured data

  • heatmap() - Color-encoded matrix with annotations
  • clustermap() - Hierarchically-clustered heatmap

Key parameters:

  • data - 2D rectangular dataset (DataFrame or array)
  • annot - Display values in cells
  • fmt - Format string for annotations (e.g., ".2f")
  • cmap - Colormap name
  • center - Value at colormap center (for diverging colormaps)
  • vmin, vmax - Color scale limits
  • square - Force square cells
  • linewidths - Gap between cells
# Correlation heatmap
corr = df.select_dtypes(include='number').corr()
sns.heatmap(corr, annot=True, fmt='.2f',
            cmap='coolwarm', center=0, square=True)

# Clustered heatmap
sns.clustermap(data, cmap='viridis',
               standard_scale=1, figsize=(10, 10))

These are selected parameters, not a union accepted by every function. Check function_reference.md for estimator, missing-data, regression, and clustering constraints. APIs reviewed against the stable API index, 2026-10-01.

Raw lines 152 to 180