Python / Data Science Essentials Interview Questions
How do you compare distributions across categories using Seaborn categorical plots?
Comparing how a numeric variable's distribution differs across groups is one of the most common analytical tasks. Seaborn's categorical plot family gives you progressively more information from left to right: bar (mean only) → box (five-number summary) → violin (full distribution shape) → strip/swarm (individual points).
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset('tips')
fig, axes = plt.subplots(2, 2, figsize=(14, 10))
# Bar plot — mean + 95% CI error bars
sns.barplot(data=tips, x='day', y='tip', hue='sex',
palette='Set2', ax=axes[0, 0])
axes[0, 0].set_title('Mean Tip by Day and Sex')
# Box plot — median, IQR, whiskers, outlier dots
sns.boxplot(data=tips, x='day', y='total_bill', hue='smoker',
palette='pastel', ax=axes[0, 1])
axes[0, 1].set_title('Total Bill Distribution by Day and Smoker')
# Violin plot — box + KDE combined
sns.violinplot(data=tips, x='day', y='tip',
inner='quartile', # show quartile lines inside
palette='muted', ax=axes[1, 0])
axes[1, 0].set_title('Tip Violin by Day')
# Strip + box overlay — all points + summary
sns.boxplot(data=tips, x='time', y='tip', color='lightblue',
ax=axes[1, 1], width=0.4)
sns.stripplot(data=tips, x='time', y='tip', color='navy',
alpha=0.4, jitter=True, ax=axes[1, 1])
axes[1, 1].set_title('Tip by Time — Box + All Points')
plt.tight_layout(); plt.show()
# Figure-level catplot for easy faceting
sns.catplot(data=tips, x='day', y='tip', hue='sex',
col='time', kind='violin', height=5, aspect=0.8)When to use each: bar plots are fine for comparing means but hide distributional information. Box plots add spread and outliers. Violin plots reveal multi-modality (two bumps indicating two groups within a category). Strip/swarm overlays add individual points, essential for small datasets where a box plot can be misleading with n < 30.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
