TutorialsPythonSeaborn for Data Visualisation

Seaborn for Data Visualisation

Create polished statistical charts in fewer lines using seaborn

Seaborn is a Python visualisation library built on matplotlib that makes statistical charts much easier. With seaborn, you can create distribution plots, box plots, correlation heatmaps, and pair plots in one or two lines. In data analyst work, seaborn is used for EDA (exploratory data analysis) — quickly understanding distributions, relationships, and patterns before building a report.

Examples

Essential seaborn charts for EDA
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("employee_salary.csv")

# Set style (do once at top of notebook)
sns.set_theme(style="whitegrid")

# HISTOGRAM — distribution of a numeric column
plt.figure(figsize=(8, 5))
sns.histplot(df["Salary"], bins=20, kde=True, color="#c47f00")
plt.title("Salary Distribution")
plt.show()

# BOX PLOT — compare distributions across categories
plt.figure(figsize=(10, 5))
sns.boxplot(x="Department", y="Salary", data=df, palette="Set2")
plt.title("Salary by Department")
plt.xticks(rotation=30)
plt.show()

# BAR PLOT with error bars
plt.figure(figsize=(8, 5))
sns.barplot(x="Region", y="Revenue", data=df, estimator="sum")
plt.title("Total Revenue by Region")
plt.show()
Correlation heatmap — most-used seaborn chart in EDA
import seaborn as sns
import matplotlib.pyplot as plt

# Correlation matrix
corr = df.select_dtypes(include="number").corr()

plt.figure(figsize=(10, 8))
sns.heatmap(
    corr,
    annot=True,        # show correlation values
    fmt=".2f",         # 2 decimal places
    cmap="coolwarm",   # diverging colour map
    center=0,          # 0 = white (no correlation)
    vmin=-1, vmax=1,
    square=True,
    linewidths=0.5
)
plt.title("Correlation Heatmap")
plt.tight_layout()
plt.show()
# High positive (red): variables move together
# High negative (blue): variables move opposite
# Near 0 (white): no linear relationship
💡 The correlation heatmap is one of the most impactful visuals you can include in an EDA report or data analyst portfolio project.

Key Points

  • sns.set_theme() at the top of your notebook sets a consistent clean style
  • kde=True in histplot adds a smooth density curve over the histogram
  • Box plot outliers appear as individual dots beyond the whiskers — seaborn shows these automatically
  • Correlation heatmap: values close to 1 or -1 are strong; near 0 are weak
  • plt.xticks(rotation=30) rotates x-axis labels to prevent overlapping

Practice Question

What does kde=True do in sns.histplot()?