0
0
Matplotlibdata~20 mins

Seaborn figure-level vs axes-level in Matplotlib - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Seaborn Plot Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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))
A<class 'seaborn.axisgrid.PairGrid'>
B<class 'matplotlib.axes._subplots.AxesSubplot'>
C<class 'matplotlib.figure.Figure'>
D<class 'seaborn.axisgrid.FacetGrid'>
Attempts:
2 left
💡 Hint
Figure-level plots return a FacetGrid object.
Predict Output
intermediate
2: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))
A<class 'seaborn.axisgrid.PairGrid'>
B<class 'matplotlib.axes._subplots.AxesSubplot'>
C<class 'matplotlib.figure.Figure'>
D<class 'seaborn.axisgrid.FacetGrid'>
Attempts:
2 left
💡 Hint
Axes-level functions return a matplotlib Axes object.
data_output
advanced
2: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))
A2
B1
C3
D0
Attempts:
2 left
💡 Hint
The col parameter creates one subplot per unique value in the column.
🔧 Debug
advanced
2: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()
AThe code works correctly and shows 3 subplots.
BThe axes array is 1D but should be flattened before use.
CThe sns.scatterplot ignores the ax parameter in this context.
DThe plt.subplots call creates only one Axes, so loop fails.
Attempts:
2 left
💡 Hint
Check how plt.subplots returns axes when rows > 1 and cols = 1.
🚀 Application
expert
3: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?
AUse Seaborn's pairplot (figure-level) with the 'hue' parameter to create the grid automatically.
BManually create matplotlib subplots and call sns.scatterplot (axes-level) on each subplot for each variable pair.
CUse sns.scatterplot (axes-level) once and rely on matplotlib's subplot adjustments.
DUse plt.plot directly without Seaborn for better control.
Attempts:
2 left
💡 Hint
Figure-level functions handle complex grids and grouping internally.