HomeCourseModule 11 › Seaborn — prettier defaults, less code

Seaborn — prettier defaults, less code

Module 11 · Data Visualization8 min readBeginner

What you'll learn

  • Use seaborn's most common charts
  • Take advantage of automatic styling
  • Plot from long-form DataFrames

Setup

import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme(style="whitegrid")

Bar chart

sns.barplot(data=df, x="region", y="amount", estimator="sum", errorbar=None)

Scatter with colour-coding

sns.scatterplot(data=df, x="qty", y="amount", hue="region")

Distribution

sns.histplot(data=df, x="amount", hue="region", multiple="stack")

Heatmap

pivot = df.pivot_table(index="dow", columns="hour",
                        values="orders", aggfunc="sum")
sns.heatmap(pivot, cmap="YlGnBu", annot=False)

Faceted small-multiples

g = sns.FacetGrid(df, col="region", col_wrap=2)
g.map_dataframe(sns.lineplot, x="date", y="amount")
💡 Seaborn loves long data
Seaborn assumes your data is in long form (one row per observation). If your data is wide, melt it first (Module 10, Lesson 6).

Key takeaways

  • Seaborn = matplotlib with prettier defaults and fewer lines.
  • Use long-form DataFrames; let hue= handle grouping.
  • Heatmaps and facets are seaborn superpowers Excel can't easily match.

Hour-of-day heatmap

Given an orders table with date+hour, build a heatmap of total orders by day-of-week × hour-of-day.

📹 Video walkthrough
A video walkthrough of this lesson will be embedded here. Until then, the written walkthrough above mirrors what the video will cover step-for-step.