InterviewsVector

Seaborn for Data Visualization in Python

Quick answer

Seaborn is a statistical plotting library built on matplotlib that produces attractive charts with concise code. It works directly with pandas DataFrames and offers high-level functions such as sns.scatterplot, sns.histplot, sns.boxplot, and sns.heatmap, plus built-in themes. Use it for fast statistical visualisation; drop to matplotlib underneath for fine-grained customisation.

Short answer: Seaborn is a statistical plotting library built on top of matplotlib. It reads pandas DataFrames directly and turns common statistical charts — scatter, histogram/KDE, box, violin, bar, heatmap — into one-line calls with attractive defaults. Reach for it for fast exploratory analysis; drop down to matplotlib underneath when you need pixel-level control.

import seaborn as sns gives you a high-level interface over matplotlib. The value is that it understands tidy DataFrames: you pass column names to x, y, and hue, and Seaborn does the grouping, aggregation, and styling for you.

import seaborn as sns
import matplotlib.pyplot as plt
 
sns.set_theme()                    # apply Seaborn's default styling
tips = sns.load_dataset("tips")    # a bundled example DataFrame

Relational plots — scatter and line

sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time")
plt.show()

Passing hue="time" colours points by the time column automatically — no manual grouping. sns.lineplot works the same way and even draws a confidence band when a category has repeated x-values.

Distributions — axes-level vs figure-level

There are two families, and mixing them up is the most common Seaborn confusion:

  • histplot / kdeplot are axes-level — they draw onto the current axes, so they compose with plt.subplots().
  • displot is figure-level — it creates and manages its own figure, so combining it with manual subplots doesn't work the way you'd expect.
# axes-level: fits into your own subplot grid
sns.histplot(data=tips, x="tip", kde=True)
 
# figure-level: manages its own figure, good for faceting with col=/row=
sns.displot(data=tips, x="tip", kde=True, col="time")

Categorical plots

sns.boxplot(data=tips, x="day", y="tip")       # spread + outliers per day
sns.violinplot(data=tips, x="day", y="tip")    # distribution shape per day
sns.barplot(data=tips, x="day", y="tip")       # MEAN tip per day, with CI

Note barplot shows the mean (with a confidence interval) by default, not a raw count — use sns.countplot when you want counts.

Correlation heatmap

A one-liner that's genuinely useful in interviews and EDA:

corr = tips.corr(numeric_only=True)
sns.heatmap(corr, annot=True, cmap="coolwarm")

Seaborn vs matplotlib — when to use which

Seaborn is matplotlib underneath, so it's not either/or. Use Seaborn for the chart, then use matplotlib's API on the returned axes for finishing touches:

ax = sns.scatterplot(data=tips, x="total_bill", y="tip")
ax.set_title("Tips vs total bill")   # matplotlib call on the Seaborn axes
ax.set_ylim(0, 12)

Use Seaborn when the chart is statistical and the data is in a DataFrame; drop to raw matplotlib for fully custom or non-statistical figures.

Sources

Key takeaways

  • Seaborn is a statistical plotting library built on matplotlib that produces attractive charts with concise code.
  • It works directly with pandas DataFrames and offers high-level functions such as scatterplot, histplot, boxplot, and heatmap.
  • Built-in themes style plots professionally by default.
  • Drop to matplotlib underneath for fine-grained customization.

Frequently asked questions

What is Seaborn used for?

Fast statistical visualisation from pandas DataFrames, with high-level chart functions and attractive default themes.

What is the difference between Seaborn and matplotlib?

Seaborn is a higher-level wrapper over matplotlib; use Seaborn for concise statistical charts and matplotlib for low-level customization.

By Mohammad Wasi

Software Engineering Leader & Technical Author · Updated September 9, 2026


Related Posts