Stop 03 · Data Manipulation & VisualizationTopics · 8/10

Seaborn

Part of the AI Engineer Roadmap

In short

Want a clean histogram split by group, or a correlation heatmap, in one line? Seaborn gives you good-looking statistical charts straight from a DataFrame, so you spend time reading charts, not styling them.

A statistical visualization library built on matplotlib with sensible defaults — the fastest way to produce clean EDA plots (distributions, correlations, categorical comparisons).

The purple blob pours a ready masala mix into a pot of colourful food.

Think of it like this

Ready-to-cook masala mix

Cooking pav bhaji from scratch means roasting and grinding a dozen spices. A good ready-mix packet gets you a tasty dish in minutes, and you can still add your own touch. Seaborn is that packet: sensible colours and layouts baked in, built on matplotlib underneath.

Watch it happen

Same histogram, split by lunch and dinner

Plain matplotlib

  • Filter each group yourself
  • Call hist twice, pick colours
  • Add the legend by hand

Seaborn

  • Pass the DataFrame and hue='time'
  • Colours and legend come automatically
  • Still returns a matplotlib Axes

Use Seaborn for quick, clear EDA charts. Drop to matplotlib when you need fine control. They mix happily in one figure.

The big ideas

What you need to know

It speaks DataFrames

Pass data=df and column names as strings. No need to pull out arrays first.

hue splits by a category

hue='smoker' colours each group differently and adds a legend. One argument, one extra dimension.

Distribution plots

histplot, kdeplot and boxplot show shape and outliers. Box plots compare groups side by side.

Relationship plots

scatterplot, heatmap of df.corr() and pairplot show how numeric columns move together.

See it in code

Walk through the code

python
1import matplotlib.pyplot as plt2import seaborn as sns3 4tips = sns.load_dataset("tips")      # downloads a small sample dataset5 6fig, axes = plt.subplots(1, 3, figsize=(15, 4))7sns.histplot(data=tips, x="total_bill", hue="time", kde=True, ax=axes[0])8sns.boxplot(data=tips, x="day", y="tip", ax=axes[1])9sns.heatmap(tips.select_dtypes("number").corr(), annot=True,10            cmap="vlag", vmin=-1, vmax=1, ax=axes[2])11axes[0].set_title("Dinner bills run higher")12plt.tight_layout()13plt.show()

1/4load_dataset fetches small example datasets from the internet. Your own data would come from read_csv.

Three common EDA charts in one figure. Because Seaborn draws onto matplotlib Axes, you can still set titles and layout the usual way.

Save yourself the pain

Common mistakes

Oops

Passing a whole DataFrame with text columns to heatmap(df.corr()).

Do this instead

Select numeric columns first with select_dtypes('number'), then compute the correlation.

Oops

Adding hue, size, style and col all at once until the chart is unreadable.

Do this instead

Add one extra dimension at a time. If it needs a paragraph to explain, split it into two charts.

Your mission

Five charts on the penguins data

~20 min

Quick check

You draw sns.histplot(data=df, x='age', hue='gender'). What does hue do here?

Go deeper

  1. 1Practice `histplot`, `boxplot`, `pairplot` and `heatmap` on a real dataset.
  2. 2Use a correlation heatmap to spot relationships between features.
  3. 3Compare the same chart in matplotlib vs. seaborn to see the productivity difference.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge