Seaborn Intermediate¶
When you'd use this
Statistical data visualization built on Matplotlib.
Make statistical plots quickly — heatmaps, distributions, pair plots — on top of matplotlib with sensible defaults.
What you'll learn¶
- What Seaborn adds over Matplotlib
- Statistical plots in one line
- The main plot categories
- Working with DataFrames
- When to use Seaborn vs Matplotlib
Seaborn is a statistical visualization library built on top of Matplotlib. It makes attractive, informative statistical graphics with far less code — and understands Pandas DataFrames directly.
Plotting libraries need install + a display
Seaborn (and Matplotlib) aren't installed in this environment and produce images, so this page follows their documented APIs rather than being run-verified. The Scientific Visualization page covers general plotting principles.
What Seaborn adds¶
A core question explored in Seaborn: What Seaborn adds.
Matplotlib is powerful but low-level — a statistical plot can take many lines. Seaborn wraps common statistical visualizations into single calls, adds attractive defaults, and speaks DataFrames:
import seaborn as sns # pip install seaborn
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips") # a built-in example DataFrame
# A scatter plot with a regression line — one call
sns.regplot(data=tips, x="total_bill", y="tip")
plt.show()
The same plot in raw Matplotlib would need manual regression fitting and styling. Seaborn does it in a line, and it looks good by default.
The main plot categories¶
Relational, distribution, categorical, and matrix plots — the Seaborn families.
Seaborn organizes plots by what they show:
| Category | Plots | Shows |
|---|---|---|
| Relational | scatterplot, lineplot | Relationship between two variables |
| Distribution | histplot, kdeplot, boxplot, violinplot | How one variable is distributed |
| Categorical | barplot, countplot, boxplot, stripplot | Comparison across categories |
| Matrix | heatmap, clustermap | 2D data, correlations |
| Multi-plot | pairplot, FacetGrid | Many relationships at once |
sns.histplot(data=tips, x="total_bill", kde=True) # distribution + density curve
sns.boxplot(data=tips, x="day", y="total_bill") # distribution per category
sns.heatmap(tips.corr(numeric_only=True), annot=True) # correlation matrix
The killer features¶
Built-in statistical estimation, faceting, and themes that Matplotlib lacks.
Two Seaborn capabilities are especially powerful:
pairplot — plot every pair of numeric columns at once, instantly revealing relationships across a whole dataset:
Semantic mapping with hue/size/style — encode extra dimensions by color, size, or marker, so one plot shows three or four variables:
These turn exploratory data analysis into a few expressive lines — a big reason Seaborn is a staple of data science notebooks.
Seaborn vs Matplotlib¶
Seaborn for fast statistical plots; drop to Matplotlib for fine control.
They're complementary, not competitors (Seaborn is Matplotlib underneath):
- Seaborn — for statistical plots, quick exploration, attractive defaults, DataFrame-native work. Reach for it first in data analysis.
- Matplotlib — for fine-grained control, custom/non-statistical plots, and final polish. You often start with Seaborn and tweak with Matplotlib (
plt.calls work on Seaborn plots).
Explore with Seaborn, polish with Matplotlib
In a typical workflow: use Seaborn to rapidly explore and understand your data (pairplot, distributions, correlations), then drop to Matplotlib for the exact styling when preparing a final figure. Since Seaborn returns Matplotlib axes, you get both.
Practice exercises¶
- Describe which Seaborn plot you'd use to see the distribution of a single numeric column.
- Explain what
hue="category"adds to a scatter plot and why it's useful. - When would you use a
boxplotvs aviolinplotfor showing distributions per category? - Describe what a
heatmapof a correlation matrix reveals at a glance. - Explain the division of labor between Seaborn and Matplotlib in a real analysis workflow.
💬 Discussion
Have a question about this topic? Found an error? Share your thoughts below.