0
0
Matplotlibdata~10 mins

Seaborn figure-level vs axes-level in Matplotlib - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Seaborn figure-level vs axes-level
Start: Choose plot type
Is plot figure-level?
YesCreate new Figure + Axes internally
Return Figure object
Is plot axes-level?
YesUse existing Axes object
Return Axes object
Error: Unknown plot type
Decide if the plot creates a new figure (figure-level) or uses an existing axes (axes-level). Figure-level plots manage the whole figure, axes-level plots draw on given axes.
Execution Sample
Matplotlib
import seaborn as sns
import matplotlib.pyplot as plt

# Figure-level plot
sns.catplot(data=tips, x='day', y='total_bill')

# Axes-level plot
fig, ax = plt.subplots()
sns.boxplot(data=tips, x='day', y='total_bill', ax=ax)
Shows how figure-level plot creates its own figure, axes-level plot uses existing axes.
Execution Table
StepActionPlot TypeFigure CreatedAxes UsedReturn Object
1Call sns.catplot()Figure-levelYes (new Figure)New Axes created internallyFacetGrid (figure-level object)
2Plot draws internallyFigure-levelYesInternal AxesFacetGrid object manages figure and axes
3Call plt.subplots()SetupYes (new Figure)New Axes returnedFigure and Axes objects
4Call sns.boxplot() with ax=axAxes-levelNo (uses existing Figure)Existing Axes passed inAxes object
5Plot draws on passed AxesAxes-levelNoExisting AxesAxes object
6End of plotting----
💡 Execution stops after plots are drawn and objects returned.
Variable Tracker
VariableStartAfter sns.catplot()After plt.subplots()After sns.boxplot()
figNoneCreated internally by catplotCreated by plt.subplots()Same as plt.subplots() figure
axNoneCreated internally by catplotCreated by plt.subplots()Passed to sns.boxplot()
plot_objNoneFacetGrid object returnedNoneAxes object returned
Key Moments - 2 Insights
Why does sns.catplot() create a new figure while sns.boxplot() can use an existing axes?
sns.catplot() is a figure-level function that manages the whole figure and creates it internally (see execution_table step 1). sns.boxplot() is axes-level and draws on an existing axes passed via the ax parameter (see step 4).
What object type is returned by figure-level vs axes-level plots?
Figure-level plots like sns.catplot() return a FacetGrid object that manages figure and axes (step 2). Axes-level plots like sns.boxplot() return the Axes object they draw on (step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is created internally by sns.catplot() at step 1?
AOnly a new Figure
BA new Figure and Axes
COnly a new Axes
DNo new objects
💡 Hint
Check the 'Figure Created' and 'Axes Used' columns at step 1 in the execution_table.
At which step does sns.boxplot() use an existing Axes object?
AStep 4
BStep 2
CStep 1
DStep 3
💡 Hint
Look at the 'Axes Used' column for sns.boxplot() in the execution_table.
If you do not pass ax to sns.boxplot(), what will happen?
AIt will create a new figure and axes internally
BIt will raise an error
CIt will plot on the last active axes
DIt will return a FacetGrid object
💡 Hint
Axes-level plots use existing axes or the current active axes if none is passed.
Concept Snapshot
Seaborn plots are either figure-level or axes-level.
Figure-level plots (e.g., catplot) create and manage their own figure and axes.
Axes-level plots (e.g., boxplot) draw on existing matplotlib axes passed via ax.
Figure-level returns a FacetGrid object; axes-level returns the Axes object.
Use figure-level for complex multi-plot layouts; axes-level for simple single plots.
Full Transcript
This visual execution trace shows the difference between Seaborn figure-level and axes-level plots. Figure-level plots like catplot create a new figure and axes internally and return a FacetGrid object that manages them. Axes-level plots like boxplot require an existing matplotlib axes object passed via the ax parameter and return that axes after drawing. The execution table traces calls and object creation step-by-step. Variable tracking shows how figure and axes variables change. Key moments clarify why figure-level plots create new figures and what objects are returned. The quiz tests understanding of which objects are created and used at each step. The concept snapshot summarizes the main differences and usage tips.