0PricingLogin
Pandas & NumPy Academy · Lesson

Categorical Plots: boxplot, barplot, violinplot

Compare distributions across groups with box plots and violin plots, and plot group means with error bars using barplot.

Why Categorical Comparison Plots?

When you want to compare a numeric variable across different categories — for example, tips received by day of the week, or product prices by brand — you need specialised plots. Seaborn provides three essential categorical comparison plots: boxplot, barplot, and violinplot. Each one reveals different aspects of the distribution and is suited to different analytical goals.

import seaborn as sns
import matplotlib.pyplot as plt

# Load the tips dataset — a classic Seaborn example
tips = sns.load_dataset('tips')
print(tips.groupby('day')['total_bill'].describe())

Box Plots with sns.boxplot

A box plot summarises a distribution using five statistics: the minimum, first quartile (Q1), median, third quartile (Q3), and maximum (excluding outliers). The box spans Q1 to Q3 (the Interquartile Range, IQR), the line inside the box is the median, and the whiskers extend to 1.5×IQR. Points beyond the whiskers are plotted individually as outliers. Box plots are excellent for spotting skewness and outliers at a glance.

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset('tips')

sns.boxplot(data=tips, x='day', y='total_bill', order=['Thur', 'Fri', 'Sat', 'Sun'])
plt.title('Total Bill Distribution by Day')
plt.xlabel('Day')
plt.ylabel('Total Bill ($)')
plt.show()

All lessons in this course

  1. Distribution Plots: histplot and kdeplot
  2. Categorical Plots: boxplot, barplot, violinplot
  3. Scatter Plots and Pair Plots
  4. Heatmaps for Correlation Matrices
← Back to Pandas & NumPy Academy