Course contentsShow
← Data Science
Lesson 1255 of 2,14532. Visualization with Matplotlib and SeabornFree lesson

The Anatomy of a Matplotlib Figure

Understanding figures, axes, and the object hierarchy that forms the foundation of all Matplotlib plots.

The Anatomy of a Matplotlib Figure

What you'll learn: How Matplotlib organizes visual elements into a hierarchical structure of figures, axes, and components.

Understanding the Matplotlib Object Hierarchy

Think of a Matplotlib visualization like a physical art gallery. The Figure is the entire building—the blank canvas or container that holds everything. Inside that building, you have individual Axes (not "axis"!)—these are the actual plot areas where your data appears, like individual paintings on a wall. A single Figure can contain multiple Axes, just as one gallery can display many artworks.

The Core Components

Figure: The top-level container. It's the whole window or page where your visualization lives. You can set its size, background color, and overall layout here.

Axes: The region where data is plotted. Each Axes contains two (or three, for 3D) Axis objects—the x-axis and y-axis with their tick marks, labels, and scales. Despite the confusing naming, one Axes has multiple Axis objects.

Axis: The number lines (x, y, or z) that provide the scale and ticks. These handle the actual numeric or categorical scales.

Artists: Everything visible on the plot—lines, text, patches, images—are "Artist" objects. This includes titles, legends, grid lines, and your actual data representations.

Why This Matters

Understanding this hierarchy lets you control every aspect of your plots precisely. You don't just make a chart and hope—you manipulate the Figure to adjust overall size, target specific Axes to modify individual subplots, and tweak Axis properties to format scales exactly as needed.

Key Takeaway: Matplotlib builds visualizations as a hierarchy: Figure (the container) → Axes (plot areas) → Axis (scales) → Artists (visual elements). Mastering this structure gives you complete control over every visualization detail.