0
0
Matplotlibdata~15 mins

Axes creation with add_subplot in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Axes Creation with add_subplot in Matplotlib
📖 Scenario: You are working on a simple data visualization project. You want to create a plot with multiple sections (subplots) to compare different data sets side by side.
🎯 Goal: Build a Python script that creates a figure and adds two subplots using add_subplot. Each subplot will later hold a different plot.
📋 What You'll Learn
Create a figure object using plt.figure()
Add a first subplot to the figure using add_subplot(1, 2, 1)
Add a second subplot to the figure using add_subplot(1, 2, 2)
Print the axes objects to confirm creation
💡 Why This Matters
🌍 Real World
Creating multiple plots in one figure helps compare data sets side by side, useful in reports and presentations.
💼 Career
Data scientists and analysts often create multi-plot figures to visualize and compare different data trends clearly.
Progress0 / 4 steps
1
Create a figure object
Write code to create a figure object called fig using plt.figure().
Matplotlib
Need a hint?

Use plt.figure() to create a new figure and assign it to fig.

2
Add the first subplot
Add a subplot to the figure fig using add_subplot(1, 2, 1) and assign it to a variable called ax1.
Matplotlib
Need a hint?

Use fig.add_subplot(1, 2, 1) to add the first subplot and save it as ax1.

3
Add the second subplot
Add a second subplot to the figure fig using add_subplot(1, 2, 2) and assign it to a variable called ax2.
Matplotlib
Need a hint?

Use fig.add_subplot(1, 2, 2) to add the second subplot and save it as ax2.

4
Print the axes objects
Print the variables ax1 and ax2 to display the axes objects created by add_subplot.
Matplotlib
Need a hint?

Use print(ax1) and print(ax2) to show the axes objects.