0
0
Matplotlibdata~5 mins

Seaborn figure-level vs axes-level in Matplotlib

Choose your learning style9 modes available
Introduction

Seaborn helps you make charts easily. Figure-level and axes-level functions decide how much control you get over the chart layout.

When you want a quick full chart with titles and legends ready.
When you want to combine multiple plots in one figure.
When you want to customize parts of the chart like axes or colors.
When you want to create complex layouts with multiple plots.
When you want to add extra decorations like titles or legends easily.
Syntax
Matplotlib
Figure-level function:
seaborn.function_name(data=..., x=..., y=..., ...)

Axes-level function:
ax = matplotlib.pyplot.subplot()
seaborn.function_name(data=..., x=..., y=..., ax=ax, ...)

Figure-level functions create the whole figure and manage layout automatically.

Axes-level functions draw on a specific part (axes) of an existing figure, giving more control.

Examples
This is a figure-level call that creates a full scatter plot with axes and legend.
Matplotlib
import seaborn as sns
sns.scatterplot(data=df, x='age', y='height')
This uses an axes-level function to draw the scatter plot on a specific axes.
Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
sns.scatterplot(data=df, x='age', y='height', ax=ax)
plt.show()
Sample Program

This code shows both figure-level and axes-level histograms of penguin flipper lengths by species. The first plot is made by seaborn managing the figure. The second plot uses matplotlib to create the figure and axes, then seaborn draws on that axes.

Matplotlib
import seaborn as sns
import matplotlib.pyplot as plt

# Sample data
penguins = sns.load_dataset('penguins')

# Figure-level plot: creates figure and axes automatically
fig1 = sns.histplot(data=penguins, x='flipper_length_mm', hue='species', multiple='stack')
plt.title('Figure-level: Flipper Length Distribution')
plt.show()

# Axes-level plot: create figure and axes first, then plot on axes
fig2, ax2 = plt.subplots()
sns.histplot(data=penguins, x='flipper_length_mm', hue='species', multiple='stack', ax=ax2)
ax2.set_title('Axes-level: Flipper Length Distribution')
plt.show()
OutputSuccess
Important Notes

Figure-level functions include: relplot, catplot, displot, pairplot, jointplot.

Axes-level functions include: scatterplot, histplot, boxplot, violinplot, kdeplot.

Use figure-level when you want quick plots with built-in layout.

Use axes-level when you want to combine plots or customize layout deeply.

Summary

Figure-level functions create the whole figure and manage layout automatically.

Axes-level functions draw on specific axes you create, giving more control.

Choose figure-level for quick, simple plots; axes-level for detailed customization.