Challenge - 5 Problems
Seaborn Plot Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of figure-level Seaborn plot
What does the following code output when run?
Matplotlib
import seaborn as sns import matplotlib.pyplot as plt iris = sns.load_dataset('iris') p = sns.catplot(x='species', y='sepal_length', data=iris) print(type(p))
Attempts:
2 left
💡 Hint
Figure-level plots return a FacetGrid object.
✗ Incorrect
Seaborn figure-level functions like catplot return a FacetGrid object that manages the entire figure and axes internally.
❓ Predict Output
intermediate2:00remaining
Output type of axes-level Seaborn plot
What is the type of object returned by this code?
Matplotlib
import seaborn as sns import matplotlib.pyplot as plt iris = sns.load_dataset('iris') ax = sns.scatterplot(x='sepal_length', y='sepal_width', data=iris) print(type(ax))
Attempts:
2 left
💡 Hint
Axes-level functions return a matplotlib Axes object.
✗ Incorrect
Seaborn axes-level functions like scatterplot return a matplotlib Axes object that you can further customize.
❓ data_output
advanced2:00remaining
Number of subplots in figure-level Seaborn plot with col parameter
How many subplots are created by this code?
Matplotlib
import seaborn as sns iris = sns.load_dataset('iris') g = sns.catplot(x='sepal_length', y='sepal_width', col='species', data=iris) print(len(g.axes.flat))
Attempts:
2 left
💡 Hint
The col parameter creates one subplot per unique value in the column.
✗ Incorrect
The 'species' column has 3 unique values, so catplot creates 3 subplots arranged in columns.
🔧 Debug
advanced2:00remaining
Why does this axes-level plot not show multiple subplots?
This code tries to create multiple subplots by species but only shows one plot. Why?
Matplotlib
import seaborn as sns import matplotlib.pyplot as plt iris = sns.load_dataset('iris') fig, axes = plt.subplots(3, 1) for ax, species in zip(axes, iris['species'].unique()): sns.scatterplot(x='sepal_length', y='sepal_width', data=iris[iris['species'] == species], ax=ax) plt.show()
Attempts:
2 left
💡 Hint
Check how plt.subplots returns axes when rows > 1 and cols = 1.
✗ Incorrect
plt.subplots(3,1) returns a 1D array of 3 Axes, so the loop assigns each scatterplot to a different subplot correctly.
🚀 Application
expert3:00remaining
Choosing figure-level vs axes-level for complex multi-plot visualization
You want to create a grid of scatterplots showing relationships between multiple variables grouped by a categorical variable. Which approach is best?
Attempts:
2 left
💡 Hint
Figure-level functions handle complex grids and grouping internally.
✗ Incorrect
Seaborn's pairplot is a figure-level function designed to create grids of plots with grouping and coloring easily, reducing manual subplot management.