Introduction
Seaborn is a statistical visualization library built on matplotlib that provides a high-level interface.
Distribution Plots
import seaborn as sns
import matplotlib.pyplot as plt
# Histogram with KDE
sns.histplot(data, kde=True)
# Box plot
sns.boxplot(x="category", y="value", data=df)
# Violin plot
sns.violinplot(x="category", y="value", data=df)
Relationship Plots
# Scatter with regression
sns.regplot(x="feature", y="target", data=df)
# Line plot with confidence interval
sns.lineplot(x="time", y="value", data=df)
# Pair plot
sns.pairplot(df, hue="category")
Categorical Plots
# Bar plot
sns.barplot(x="category", y="value", data=df)
# Count plot
sns.countplot(x="category", data=df)
# Heatmap
sns.heatmap(correlation_matrix, annot=True)
Practice Problems
- Create distribution of ages in dataset
- Visualize correlation matrix as heatmap
- Build pair plot for feature comparison
- Compare categories with box plot
- Add regression line to scatter plot