← 30 Days of Python
Day 18 / 30Seaborn

Seaborn — Statistical Visualisation

Seaborn produces beautiful statistical charts with minimal code. It handles colour palettes, statistical summaries, and grouping automatically. Most companies use Seaborn for analytical charts.

1
Easy

How do you create a box plot with Seaborn?

Python Answer
import seaborn as sns

fig, ax = plt.subplots(figsize=(10, 6))
sns.boxplot(
    data=df, x="department", y="salary",
    palette="Set2", ax=ax
)
ax.set_title("Salary Distribution by Department")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
💡

Box plots show median, quartiles, and outliers simultaneously — much more informative than a bar chart showing just the mean. palette="Set2" is a good colour-blind-friendly palette.

2
Medium

How do you create a heatmap for correlation?

Python Answer
corr = df[["salary","age","experience","score"]].corr()

fig, ax = plt.subplots(figsize=(8, 6))
sns.heatmap(
    corr, annot=True, fmt=".2f",
    cmap="RdYlGn", center=0,
    square=True, ax=ax
)
ax.set_title("Correlation Matrix")
plt.show()
💡

annot=True shows the numbers. fmt=".2f" formats to 2 decimal places. center=0 ensures 0 correlation is white, positive is green, negative is red. Essential for feature selection in any ML or analytics project.

3
Easy

How do you create a count plot and bar plot in Seaborn?

Python Answer
# Count plot — counts category frequency:
sns.countplot(data=df, x="city", palette="Blues_d", order=df["city"].value_counts().index)

# Bar plot — aggregated value:
sns.barplot(data=df, x="department", y="salary", estimator="mean", palette="Set1")
💡

countplot() is for frequency distributions — equivalent to value_counts() visualised. order= sorts bars by frequency. barplot() aggregates by mean by default and shows confidence intervals automatically.

4
Medium

How do you create a pair plot for EDA?

Python Answer
sns.pairplot(
    df[["salary","age","experience","score"]],
    diag_kind="hist",
    plot_kws={"alpha": 0.5}
)
plt.show()
💡

pairplot() creates a grid of scatter plots for every pair of numeric columns, with histograms on the diagonal. It is the fastest way to spot correlations and outliers across all numeric columns at once — essential for EDA.

5
Medium

How do you visualise a distribution with histplot and kdeplot?

Python Answer
fig, axes = plt.subplots(1, 2, figsize=(14, 5))

# Histogram with KDE overlay:
sns.histplot(df["salary"], kde=True, ax=axes[0], color="#FF6B00")
axes[0].set_title("Salary Distribution")

# KDE only (smooth density):
sns.kdeplot(df["salary"], ax=axes[1], fill=True, color="#1d4ed8")
axes[1].set_title("Salary Density")

plt.tight_layout()
plt.show()
💡

kde=True overlays a smooth density curve on the histogram. kdeplot() shows only the density curve — useful for comparing distributions of two groups on the same axes.

EVIKA ACADEMY · PYTHON FOR DATA ANALYTICS

Want to master Python with live practice?

Join our Python for Data Analysis course — live classes in Noida and online across India.

Book Free Demo Class →
← PREVIOUSDay 17: Matplotlib — Charts & PlotsNEXT →Day 19: EDA — Exploratory Data Analysis Workflow
Best Data Analytics Course in Noida Delhi NCR | EVIKA ACADEMY