Seaborn helps you make charts easily. Figure-level and axes-level functions decide how much control you get over the chart layout.
Seaborn figure-level vs axes-level in 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.
import seaborn as sns sns.scatterplot(data=df, x='age', y='height')
import matplotlib.pyplot as plt fig, ax = plt.subplots() sns.scatterplot(data=df, x='age', y='height', ax=ax) plt.show()
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.
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()
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.
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.