Categorical Plots: boxplot, violinplot, and countplot0%
Categorical Plots: boxplot, violinplot, and countplot
Beginner12 min read•Updated: Jul 11, 2026
Categorical Plots: boxplot, violinplot, and countplot
Reading Time: 8 Mins | Level: Intermediate
1. Comparing Distributions Across Categorical Groups
To compare numerical distributions across discrete categories, Seaborn provides:
sns.boxplot(): Shows the 5-number statistical summary (Min, Q1, Median, Q3, Max) and identifies outliers.sns.violinplot(): Combines a box plot with a rotated kernel density curve to reveal multimodal shapes.sns.countplot(): Displays frequency counts for categorical variables (like an automatedvalue_counts()).
2. Anatomy of a Box Plot
A Box Plot (Box-and-Whisker) provides 5 key metrics:
- 1Median (Q2 / 50th percentile): The central line inside the box.
- 2First Quartile (Q1 / 25th percentile): Bottom of the box.
- 3Third Quartile (Q3 / 75th percentile): Top of the box.
- 4Interquartile Range (IQR): $IQR = Q3 - Q1$ (the middle 50% of the data).
- 5Whiskers: Extend to $1.5 imes IQR$ from Q1 and Q3. Points beyond whiskers are plotted as individual outlier markers!
Python
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('tips')
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
# 1. Box Plot with Outliers
sns.boxplot(data=df, x='day', y='total_bill', palette='Set2', ax=axes[0])
axes[0].set_title('Total Bill by Day (Box Plot)')
# 2. Violin Plot (Shows Bimodal Peaks)
sns.violinplot(data=df, x='day', y='total_bill', palette='Set2', inner='quartile', ax=axes[1])
axes[1].set_title('Total Bill Density by Day (Violin Plot)')
plt.show()
Interactive Quiz
Multiple Choice Questions
Question 1
In a standard Tukey Box Plot, how is the Interquartile Range (IQR) calculated?
Question 2
In a box plot, data points that lie beyond which threshold are marked as outliers?
Question 3
What unique insight does a Violin Plot show that a standard Box Plot conceals?
Question 4
Which Seaborn function plots the frequency count of each categorical value without requiring pre-aggregation?
Question 5
What does the central line inside a box plot's rectangular box represent?
Next Lesson
Relational Plots: scatterplot with hue & size mapping
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Distribution Plots: histplot, kdeplot, and ecdfplot | Relational Plots: scatterplot with hue & size mapping |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.