Python / Data Science Essentials Interview Questions
How do Seaborn jointplot and pairplot help explore multivariate relationships?
When you have more than one numeric variable, the next step after individual histograms is to understand relationships between pairs. Seaborn's jointplot and pairplot automate this exploration with minimal code.
import seaborn as sns
import matplotlib.pyplot as plt
penguins = sns.load_dataset('penguins').dropna()
# --- jointplot: one pair of variables ---
# Scatter + marginal histograms
sns.jointplot(data=penguins, x='bill_length_mm', y='bill_depth_mm',
hue='species', height=6)
# Regression + 95% confidence interval
sns.jointplot(data=penguins, x='flipper_length_mm', y='body_mass_g',
kind='reg', height=6)
# Hex bins — better than scatter for large datasets with overplotting
sns.jointplot(data=penguins, x='flipper_length_mm', y='body_mass_g',
kind='hex', height=6)
# KDE — smooth 2-D density
sns.jointplot(data=penguins, x='bill_length_mm', y='bill_depth_mm',
kind='kde', fill=True, height=6)
# --- pairplot: all pairs + diagonal histograms ---
# Standard scatter matrix
sns.pairplot(penguins, hue='species',
diag_kind='kde', # diagonal: KDE instead of histogram
plot_kws={'alpha': 0.5}, # semi-transparent points
height=2.5)
plt.suptitle('Penguin Feature Pairs', y=1.02)
plt.show()
# Subset of columns only
cols = ['bill_length_mm', 'flipper_length_mm', 'body_mass_g']
sns.pairplot(penguins[cols + ['species']], hue='species')Use jointplot when you want to focus deeply on one specific pair of variables with marginal distributions visible. Use pairplot for a broad overview of all pairwise relationships in a dataset with up to ~10 variables — beyond that the grid becomes too small to read meaningfully.
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...
