Python / Data Science Essentials Interview Questions
What is Seaborn's FacetGrid and how does it enable multi-panel statistical plots?
FacetGrid is Seaborn's mechanism for trellis/small-multiples plots — the same chart repeated across different subsets of the data, defined by one or more categorical columns. It is one of Seaborn's most powerful features for exploring interaction effects between variables.
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset('tips')
# --- FacetGrid manually ---
g = sns.FacetGrid(tips, col='time', row='sex', height=3, aspect=1.2)
g.map_dataframe(sns.histplot, x='total_bill', bins=15, kde=True)
g.add_legend()
g.set_titles(col_template='{col_name} service', row_template='Sex: {row_name}')
g.set_axis_labels('Total Bill ($)', 'Count')
# --- Figure-level functions (wrap FacetGrid automatically) ---
# relplot — relational
sns.relplot(data=tips, x='total_bill', y='tip',
col='smoker', hue='sex', kind='scatter', height=4)
# displot — distributional
sns.displot(data=tips, x='total_bill',
col='sex', row='time', kind='kde', fill=True)
# catplot — categorical
sns.catplot(data=tips, x='day', y='tip',
col='sex', kind='violin', height=5, aspect=0.8)The figure-level functions (relplot, displot, catplot) return a FacetGrid object, not an Axes. To customise them after creation you call FacetGrid methods like g.set_titles(), g.set_axis_labels(), or iterate over g.axes.flatten() to access individual Axes objects and apply standard Matplotlib customisation.
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...
