Seaborn
01 / 02

Statistical Plots & Distributions

Statistical Plots & Distributions

Relationships

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style='whitegrid', palette='deep')  # global look for every plot after this

sns.scatterplot(data=df, x='gdp', y='life_expectancy', hue='continent')
plt.title('GDP vs Life Expectancy')  # Seaborn returns real Matplotlib axes —
plt.show()                            # standard plt.* calls still work on top

# lineplot auto-aggregates repeated x-values into a mean + CI band —
# only meaningful when there ARE genuinely repeated, independent observations
# per x-value; don't trust the band blindly if that assumption doesn't hold
sns.lineplot(data=df, x='year', y='revenue')

Distributions

sns.histplot(data=df, x='value', kde=True, bins=30)

# Box plot: quartiles/median/outliers only — can hide bimodality entirely
sns.boxplot(data=df, x='category', y='value')

# Violin plot: adds a kernel density estimate on top of the box summary —
# reveals multiple peaks a box plot's quartiles alone would completely miss
sns.violinplot(data=df, x='category', y='value')

Correlation Heatmaps & Pairwise Overview

sns.heatmap(df.corr(numeric_only=True), annot=True, cmap='coolwarm')

# Quick overview of every pairwise numeric relationship in one call —
# histograms/KDE on the diagonal, scatter plots off-diagonal
sns.pairplot(df, hue='category')

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free