Bird
Raised Fist0
Matplotlibdata~20 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. Which of the following best describes a figure-level function in Seaborn?
easy
A. It creates a complete plot including figure and axes automatically.
B. It only modifies existing axes without creating a new figure.
C. It is used to customize axis labels after plotting.
D. It requires manual creation of figure and axes before plotting.

Solution

  1. Step 1: Understand figure-level function role

    Figure-level functions in Seaborn create the entire plot including figure and axes automatically.
  2. Step 2: Compare with axes-level functions

    Axes-level functions only draw on existing axes and do not create the figure.
  3. Final Answer:

    It creates a complete plot including figure and axes automatically. -> Option A
  4. Quick Check:

    Figure-level = creates full plot [OK]
Hint: Figure-level functions create whole plots; axes-level modify existing axes [OK]
Common Mistakes:
  • Confusing figure-level with axes-level functions
  • Thinking figure-level functions require manual axes creation
  • Assuming axes-level functions create figures automatically
2. Which of the following is the correct way to use an axes-level function in Seaborn on existing axes?
easy
A. sns.scatterplot(data=df, x='age', y='height')
B. sns.scatterplot(ax=ax, data=df, x='age', y='height')
C. sns.relplot(data=df, x='age', y='height')
D. sns.relplot(ax=ax, data=df, x='age', y='height')

Solution

  1. Step 1: Identify axes-level function usage

    Axes-level functions like scatterplot can accept an ax parameter to plot on existing axes.
  2. Step 2: Check options for correct syntax

    sns.scatterplot(ax=ax, data=df, x='age', y='height') correctly passes ax=ax to scatterplot, an axes-level function.
  3. Final Answer:

    sns.scatterplot(ax=ax, data=df, x='age', y='height') -> Option B
  4. Quick Check:

    Axes-level functions use ax= parameter [OK]
Hint: Axes-level functions accept ax= parameter to plot on existing axes [OK]
Common Mistakes:
  • Using figure-level functions with ax= parameter (not supported)
  • Confusing relplot (figure-level) with scatterplot (axes-level)
  • Omitting ax= when plotting on existing axes
3. What will the following code output?
import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset('tips')
fig, ax = plt.subplots()
sns.scatterplot(data=df, x='total_bill', y='tip', ax=ax)
plt.title('Scatterplot on existing axes')
plt.show()
medium
A. A scatterplot of total_bill vs tip on a new figure with default title
B. An empty plot with no points
C. A scatterplot of total_bill vs tip on the existing axes with custom title
D. An error because scatterplot cannot accept ax parameter

Solution

  1. Step 1: Analyze code creating figure and axes

    The code creates a figure and axes with plt.subplots() and stores axes in ax.
  2. Step 2: Understand scatterplot with ax parameter

    scatterplot is axes-level and plots on the given ax. Title is set on the figure.
  3. Final Answer:

    A scatterplot of total_bill vs tip on the existing axes with custom title -> Option C
  4. Quick Check:

    Axes-level plot on existing axes = scatterplot with ax= [OK]
Hint: Axes-level plots use ax= to draw on existing axes [OK]
Common Mistakes:
  • Expecting scatterplot to create new figure automatically
  • Thinking ax= causes error with scatterplot
  • Assuming title applies only to figure-level plots
4. Identify the error in this code snippet:
import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset('tips')
fig, ax = plt.subplots()
sns.relplot(data=df, x='total_bill', y='tip', ax=ax)
plt.show()
medium
A. plt.show() must be called before relplot
B. plt.subplots() is missing required arguments
C. DataFrame 'df' is not loaded correctly
D. relplot does not accept ax parameter; it creates its own figure

Solution

  1. Step 1: Check relplot function parameters

    relplot is a figure-level function and does not accept an ax parameter.
  2. Step 2: Understand error cause

    Passing ax=ax to relplot causes an error because it manages figure creation internally.
  3. Final Answer:

    relplot does not accept ax parameter; it creates its own figure -> Option D
  4. Quick Check:

    Figure-level functions ignore ax= and raise error if given [OK]
Hint: Figure-level functions like relplot do NOT accept ax= [OK]
Common Mistakes:
  • Passing ax= to figure-level functions
  • Confusing relplot with scatterplot usage
  • Assuming plt.subplots() is incorrect here
5. You want to create a figure with two different plots side by side: a histogram and a scatterplot. Which approach correctly uses Seaborn's figure-level and axes-level functions together?
hard
A. Use sns.histplot() on one axes and sns.scatterplot() on another axes created by plt.subplots().
B. Use sns.relplot() twice, each creating its own figure, then combine figures manually.
C. Use sns.histplot() with ax= parameter and sns.relplot() without ax= on the same axes.
D. Use sns.relplot() with ax= parameter for both plots on shared axes.

Solution

  1. Step 1: Understand figure-level vs axes-level functions

    relplot is figure-level and creates its own figure; histplot and scatterplot are axes-level and can plot on existing axes.
  2. Step 2: Plan side-by-side plots

    Creating subplots with plt.subplots() and plotting axes-level functions on each axes allows side-by-side plots in one figure.
  3. Step 3: Evaluate options

    Use sns.histplot() on one axes and sns.scatterplot() on another axes created by plt.subplots(). correctly uses axes-level functions on subplots. Options A, B, and D misuse figure-level functions or ax= parameter.
  4. Final Answer:

    Use sns.histplot() on one axes and sns.scatterplot() on another axes created by plt.subplots(). -> Option A
  5. Quick Check:

    Axes-level functions + subplots = combined figure [OK]
Hint: Use axes-level functions with plt.subplots() for combined plots [OK]
Common Mistakes:
  • Trying to use relplot with ax= parameter
  • Using multiple figure-level functions expecting one figure
  • Mixing figure-level and axes-level functions on same axes