Challenge - 5 Problems
FacetGrid Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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()))
Attempts:
2 left
💡 Hint
Think about how many unique species are in the penguins dataset.
✗ Incorrect
FacetGrid with col='species' creates one panel per unique species. The penguins dataset has 3 species, so 3 panels are created.
❓ data_output
intermediate2: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()))
Attempts:
2 left
💡 Hint
Count unique values in 'island' and 'species' columns.
✗ Incorrect
There are 3 unique islands and 3 unique species, so total panels = 3 * 3 = 9.
❓ visualization
advanced2: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?
Attempts:
2 left
💡 Hint
Remember the parameters row, col, and hue correspond to rows, columns, and colors respectively.
✗ Incorrect
The FacetGrid parameters map directly: row='sex' means rows are sex categories, col='island' means columns are islands, and hue='species' means colors show species.
🔧 Debug
advanced2: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?
Attempts:
2 left
💡 Hint
Check the expected input types for functions used with FacetGrid.map.
✗ Incorrect
FacetGrid.map passes arrays to the plotting function, but sns.histplot expects a DataFrame or Series, causing a TypeError.
🚀 Application
expert3: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?
Attempts:
2 left
💡 Hint
FacetGrid works best with pre-aggregated data for bar plots when grouping by multiple variables.
✗ Incorrect
Option C correctly aggregates mean body mass by species and island, resets index for DataFrame format, and uses FacetGrid with appropriate row and col to show bars.