Data Visualization

Seaborn

01 · What is Seaborn? File · Seaborn · 1 of 10

What is Seaborn?

Seaborn is a high-level Python data visualization library built on top of Matplotlib and closely integrated with Pandas.

It simplifies creating complex statistical graphics by automating semantic and statistical aggregations.

Seaborn helps us turn a dataset into charts that answer business questions.

Python
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
Always import Seaborn as sns. It works together with Matplotlib and Pandas.
Seaborn uses Matplotlib under the hood, so you still need plt.show() to display plots.
02 · Why Seaborn? File · Seaborn · 2 of 10

Why Do We Need Seaborn?

Imagine a bank manager has thousands of customer forms. The manager wants to know:

  1. How many customers subscribed?
  2. Which occupations had higher subscription rates?
  3. What ages were commonly contacted?
  4. Do subscribers have different balance distributions?
  5. How do outcomes vary by contact method?

Reading thousands of rows makes these patterns difficult to see. Charts make them easier to investigate.

Seaborn is especially powerful because it works directly with Pandas DataFrames and automatically handles statistical aggregations (mean, count, distribution, etc.).
03 · Loading Datasets File · Seaborn · 3 of 10

Loading Datasets

Seaborn comes with several built-in datasets that are perfect for practice.

Python
# Load a built-in dataset
tips = sns.load_dataset("tips")
print(tips.head())

# Or use your own Pandas DataFrame
bank = pd.read_csv("bank_market.csv")
Popular built-in datasets: tips, iris, titanic, penguins, flights.
You can also pass any Pandas DataFrame to Seaborn plotting functions.
04 · Relational Plots File · Seaborn · 4 of 10

Relational Plots (scatterplot & lineplot)

Used to show the relationship between two numerical variables.

Python
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time")
plt.title("Total Bill vs Tip")
plt.show()
Graph – Scatterplot
Total Bill vs Tip total_bill tip Lunch Dinner
Points colored by time of day (hue="time")
Python
sns.lineplot(data=tips, x="size", y="total_bill")
plt.show()
The hue parameter automatically colors the points by a categorical variable.
sns.lineplot is useful when you want to show trend across ordered values.
05 · Distribution Plots File · Seaborn · 5 of 10

Distribution Plots

These plots help us understand the distribution of a single variable.

Python
# Histogram + KDE
sns.histplot(data=tips, x="total_bill", kde=True)
plt.show()
Graph – Histogram + KDE
total_bill Distribution
Python
# Box plot
sns.boxplot(data=tips, x="day", y="total_bill")
plt.show()
Graph – Box Plot
total_bill by day Thur Fri Sat Sun
histplot with kde=True shows both the histogram bars and a smooth density curve.
boxplot shows median, quartiles and possible outliers for each category.
06 · Categorical Plots File · Seaborn · 6 of 10

Categorical Plots

Useful when one of the variables is categorical.

Python
# Count plot
sns.countplot(data=tips, x="day", hue="sex")
plt.show()
Graph – Count Plot
Count by day and sex Thur Fri Sat Sun Male Female
Python
# Bar plot (shows mean by default)
sns.barplot(data=tips, x="day", y="total_bill", hue="sex")
plt.show()
countplot shows the number of observations in each category.
barplot shows the average (mean) of a numeric variable for each category.
07 · Heatmaps File · Seaborn · 7 of 10

Heatmaps

Heatmaps are excellent for showing correlation matrices.

Python
# Correlation heatmap
corr = tips.corr(numeric_only=True)
sns.heatmap(corr, annot=True, cmap="coolwarm", fmt=".2f")
plt.title("Correlation Heatmap")
plt.show()
Graph – Correlation Heatmap
Correlation Heatmap 1.00 0.68 0.46 0.12 total_bill tip size price
annot=True shows the correlation values on the heatmap.
cmap="coolwarm" uses a red-blue color scale (red = strong positive, blue = strong negative).
08 · Pair Plots File · Seaborn · 8 of 10

Pair Plots

A pair plot shows relationships between all pairs of numerical variables in one figure.

Python
sns.pairplot(tips, hue="sex")
plt.show()
Graph – Pair Plot (schematic)
Pair Plot Overview hist scatter scatter
Diagonal = distribution, Off-diagonal = scatter plots
Very useful for quick exploratory data analysis (EDA).
The diagonal shows the distribution of each variable. The other cells show scatter plots between pairs of variables.
09 · Themes & Styles File · Seaborn · 9 of 10

Themes and Styles

Seaborn makes it easy to change the overall look of your plots.

Python
# Set a theme
sns.set_theme(style="whitegrid")

# Other styles: "darkgrid", "white", "dark", "ticks"
sns.set_style("darkgrid")

# Change palette
sns.set_palette("pastel")

sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time")
plt.show()
Available styles: "darkgrid", "whitegrid", "dark", "white", "ticks".
Palettes control the color scheme used for categories ("pastel", "deep", "muted", "bright", etc.).
10 · Real Business Example File · Seaborn · 10 of 10

Real Business Example (Bank Marketing)

Using the bank marketing dataset to answer business questions with Seaborn.

Python
# How many customers subscribed?
sns.countplot(data=bank, x="y")
plt.title("Subscription Count")
plt.show()
Graph – Subscription Count
Subscription Count no yes ~88% ~12%
Python
# Subscription rate by job
sns.countplot(data=bank, y="job", hue="y",
            order=bank["job"].value_counts().index)
plt.title("Subscription by Job")
plt.show()
Python
# Age distribution of subscribers vs non-subscribers
sns.histplot(data=bank, x="age", hue="y", kde=True)
plt.title("Age Distribution by Subscription")
plt.show()
These three plots answer key business questions:
1. Overall subscription rate
2. Which jobs convert better
3. Whether age distribution differs between subscribers and non-subscribers
Home Seaborn

Seaborn — High-level Statistical Visualization

Create beautiful statistical charts easily with Pandas + Matplotlib power underneath.

Select any topic from the left sidebar to begin.


Start Learning →