Understanding Figure and Axes
The Figure and Axes are the two most important objects in Matplotlib. Understanding them is key to creating any visualization.
The Hierarchy
Matplotlib organizes plots in a hierarchy:
Figure (the overall window/canvas)
โโโ Axes (an individual plot/chart)
โโโ XAxis (the x-axis)
โโโ YAxis (the y-axis)
โโโ Title
โโโ Lines, Bars, etc. (the actual data)
โโโ Legend, Grid, etc.
Creating Figures and Axes
There are several ways to create figures and axes:
Method 1: plt.subplots() (Recommended)
Method 2: plt.figure() + add_subplot()
Figure Properties
The Figure object controls the overall appearance:
Axes Properties
Each Axes object has many customizable properties:
Working with Multiple Axes
Grid of Subplots
Shared Axes
Adjusting Spacing
Practice: Create a Multi-Panel Figure
Key Takeaways
- Figure is the overall container (like a canvas or window)
- Axes is an individual plot within the figure
- Use
plt.subplots(rows, cols)to create figures with multiple axes - Access axes in a grid using
axes[row, col]indexing - Customize figures with
figsize,facecolor,dpi - Customize axes with
set_title(),set_xlabel(),set_xlim(),set_xticks() - Use
sharex=Trueorsharey=Truefor linked axes - Use
plt.tight_layout()for automatic spacing
In the next lesson, we'll explore the basic plotting commands you'll use most often.
Up next ยท Lesson 7 of 38
Basic Plotting Commands
1 min read
6 of 38 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

