0
0
Data Analysis Pythondata~20 mins

FacetGrid for multi-panel views in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FacetGrid Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of FacetGrid with hue and col
What is the output of the following code snippet using seaborn's FacetGrid?
Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt

penguins = sns.load_dataset('penguins')
g = sns.FacetGrid(penguins, col='species', hue='sex')
g.map(plt.scatter, 'bill_length_mm', 'bill_depth_mm').add_legend()
plt.close()  # Prevent plot display in test environment
print(len(g.axes.flatten()))
A3
B2
C1
D4
Attempts:
2 left
💡 Hint
Think about how many unique species are in the penguins dataset.
data_output
intermediate
2:00remaining
Number of panels in FacetGrid with row and col
Given the following code, how many total panels will the FacetGrid create?
Data Analysis Python
import seaborn as sns
penguins = sns.load_dataset('penguins')
g = sns.FacetGrid(penguins, row='island', col='species')
print(len(g.axes.flatten()))
A3
B9
C6
D12
Attempts:
2 left
💡 Hint
Count unique values in 'island' and 'species' columns.
visualization
advanced
2:00remaining
Identify the FacetGrid layout from the plot description
You create a FacetGrid with parameters row='sex', col='island', and hue='species'. Which layout best describes the resulting grid?
ARows represent species; columns represent sex; colors represent islands.
BRows represent islands; columns represent species; colors represent sex.
CRows represent species; columns represent islands; colors represent sex.
DRows represent male and female; columns represent islands; colors represent species.
Attempts:
2 left
💡 Hint
Remember the parameters row, col, and hue correspond to rows, columns, and colors respectively.
🔧 Debug
advanced
2:00remaining
Why does this FacetGrid code raise an error?
Consider this code snippet: import seaborn as sns import matplotlib.pyplot as plt penguins = sns.load_dataset('penguins') g = sns.FacetGrid(penguins, col='species', row='sex') g.map(sns.histplot, 'flipper_length_mm') plt.show() Why does this code raise an error?
Asns.histplot cannot be used with FacetGrid.map because it expects a DataFrame, not arrays.
BThe 'sex' column contains missing values causing the FacetGrid to fail.
CThe map function requires matplotlib.pyplot functions, not seaborn functions.
DFacetGrid requires numeric columns for row and col parameters, but 'sex' is categorical.
Attempts:
2 left
💡 Hint
Check the expected input types for functions used with FacetGrid.map.
🚀 Application
expert
3:00remaining
Create a FacetGrid showing mean body mass per species and island
You want to create a FacetGrid that shows the mean body mass (in grams) for each species on each island. Which approach correctly prepares the data and creates the FacetGrid?
AUse sns.FacetGrid(penguins, col='species', row='island').map(sns.barplot, 'species', 'body_mass_g') directly on raw data.
BUse penguins.pivot_table(index='species', columns='island', values='body_mass_g', aggfunc='mean') and plot with FacetGrid using col='species'.
CUse penguins.groupby(['species', 'island'])['body_mass_g'].mean().reset_index() and then sns.FacetGrid with col='species', row='island' mapping sns.barplot with x='island', y='body_mass_g'.
DUse sns.FacetGrid(penguins, col='species').map(sns.barplot, 'island', 'body_mass_g') without aggregation.
Attempts:
2 left
💡 Hint
FacetGrid works best with pre-aggregated data for bar plots when grouping by multiple variables.