0PricingLogin
Pandas & NumPy Academy · Lesson

Figure and Axes Architecture

Understand the Figure-Axes-Artist hierarchy, create plots with plt.subplots(), and differentiate the stateless and object-oriented APIs.

Why Learn Matplotlib Architecture?

Pandas and Seaborn both use Matplotlib internally. Understanding Matplotlib's object hierarchy lets you control every aspect of a plot — from the overall canvas to individual tick marks — and lets you combine multiple charts in a single figure. Without understanding the Figure-Axes model, customising plots quickly becomes a frustrating exercise in guessing which function to call.

The Figure: The Canvas

A Figure is the outermost container — the entire window or image file. It holds one or more Axes objects (the actual plot areas), plus a title, shared legends, and whitespace. You create a Figure with plt.figure() or implicitly through plt.subplots(). Most properties set on the Figure affect the whole canvas: size, background colour, overall title.

import matplotlib.pyplot as plt
import numpy as np

# Create a Figure with a specific size
fig = plt.figure(figsize=(8, 4))  # width=8 inches, height=4 inches
print(type(fig))  # matplotlib.figure.Figure
print('Figure size:', fig.get_size_inches())
plt.close()  # close to avoid display in scripts

All lessons in this course

  1. Figure and Axes Architecture
  2. Line and Scatter Plots
  3. Bar Charts and Histograms
  4. Labels, Titles, and Saving Figures
← Back to Pandas & NumPy Academy