Monday , November 30 2026
Seaborn tutorial with examples: histplot, boxplot, violinplot, barplot, countplot, scatterplot, regplot, pairplot and heatmap, plus how to choose a plot.

Seaborn Tutorial: Statistical Data Visualization in Python

Updated: 29 November 2026Level: BeginnerReading time: about 10 minutesSeaborn 0.13 · tested

Seaborn is a Python visualisation library built on Matplotlib. It works directly with pandas DataFrames and makes attractive statistical charts – distributions, comparisons and relationships – in one line each.

What You Will Learn

  • Install and set a theme
  • Distribution plots: histplot, kdeplot, boxplot, violinplot
  • Category plots: barplot, countplot
  • Relationship plots: scatterplot, regplot, lmplot, pairplot
  • Heatmaps and saving figures

Prerequisites

EDA – examples use the cleaned emp.csv.

Setup

Example
# pip install seaborn
import pandas as pd, seaborn as sns, matplotlib.pyplot as plt
df = pd.read_csv("emp.csv")
df = df[df.salary < 120850]           # remove the error row and missing values
sns.set_theme(style="whitegrid")

Distributions

Example
sns.histplot(data=df, x="salary", bins=20, kde=True)
plt.title("Salary distribution"); plt.show()

Explanation: A histogram with a smoothed KDE curve shows the shape of one numeric variable. Use hue="city" to overlay groups.

Example
sns.boxplot(data=df, x="city", y="salary"); plt.show()
sns.violinplot(data=df, x="city", y="salary"); plt.show()

Explanation: Box plots show median, quartiles and outliers per group; violin plots add the full distribution shape.

Categories

Example
sns.countplot(data=df, x="city"); plt.show()
sns.barplot(data=df, x="city", y="salary", estimator="median", errorbar=None); plt.show()

Explanation: countplot counts rows per category. barplot aggregates a numeric column (mean by default; here median). In Seaborn 0.12+ use errorbar=None instead of the old ci=None.

Relationships

Example
sns.scatterplot(data=df, x="experience", y="salary", hue="city"); plt.show()
sns.regplot(data=df, x="experience", y="salary"); plt.show()
sns.lmplot(data=df, x="experience", y="salary", col="city"); plt.show()

Explanation: scatterplot colours points by group. regplot adds a regression line with a confidence band. lmplot draws one panel per city (a facet).

Example
sns.pairplot(df, hue="city"); plt.show()

Explanation: pairplot draws every numeric pair as scatter plots and each variable’s distribution on the diagonal – a quick EDA overview.

Heatmap

Example
corr = df[["age", "experience", "salary"]].corr()
sns.heatmap(corr, annot=True, cmap="coolwarm", vmin=-1, vmax=1); plt.show()

Explanation: Shows the correlation matrix with values printed. Fixing vmin/vmax to −1…1 keeps colours comparable across charts.

Save a Figure

Example
ax = sns.boxplot(data=df, x="city", y="salary")
ax.set(xlabel="City", ylabel="Salary (₹)")
plt.tight_layout(); plt.savefig("salary_by_city.png", dpi=150)

Which Plot to Use

Question Plot
Shape of one variable histplot, kdeplot
Compare groups boxplot, violinplot, barplot
How many per category countplot
Two numeric variables scatterplot, regplot
Same chart per group lmplot, relplot, catplot (col=…)
All pairs at once pairplot
Matrix of values heatmap
Seaborn vs Matplotlib Seaborn Matplotlib
Level High-level, statistical Low-level, full control
Input DataFrames and column names Arrays
Defaults Polished themes Plain
Use together? Yes – Seaborn returns Matplotlib axes you can customise

Series

Data Science series: What is Data Science · Lifecycle · Data Cleaning · EDA · Outliers · Feature Engineering · Visualization · Seaborn · Roadmap

Interview Questions

Q: Difference between barplot and countplot?
countplot counts rows; barplot aggregates a numeric y value per category.

Q: What does hue do?
Splits the data by a categorical column and colours each group differently.

Practice Exercises

  1. Draw a violin plot of salary by experience level (see Feature Engineering).
  2. Load sns.load_dataset(“tips”) and plot tip vs total_bill coloured by time.

Summary

Seaborn turns DataFrame columns into statistical charts with one call: hist/box/violin for distributions, bar/count for categories, scatter/reg/pair for relationships and heatmap for matrices.

Next: Data Visualization in pandas · Data Scientist Roadmap

About Machine Learning

Check Also

Outlier Detection in Python: IQR, Z-Score and Isolation Forest

Detect and handle outliers in pandas with the IQR rule, z-scores and Isolation Forest, with tested outputs showing how one bad value distorts results.