0
0
Matplotlibdata~15 mins

Subplot spacing adjustment in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Subplot spacing adjustment
📖 Scenario: You are creating a simple report with multiple charts side by side. To make the report look neat, you need to adjust the space between the charts.
🎯 Goal: Learn how to create multiple subplots using matplotlib and adjust the spacing between them using plt.subplots_adjust().
📋 What You'll Learn
Create a figure with 2 subplots side by side
Set the horizontal space between subplots to 0.5
Display the figure with adjusted spacing
💡 Why This Matters
🌍 Real World
Adjusting subplot spacing helps make charts in reports or presentations look neat and easy to read.
💼 Career
Data scientists and analysts often create multiple charts together and need to control layout for better visualization.
Progress0 / 4 steps
1
Create two subplots side by side
Write code to create a figure and two subplots side by side using plt.subplots() with nrows=1 and ncols=2. Store the result in variables fig and axes.
Matplotlib
Need a hint?

Use plt.subplots(nrows=1, ncols=2) to create two subplots in one row.

2
Set horizontal spacing between subplots
Create a variable called hspace and set it to 0.5. This will control the horizontal space between the subplots.
Matplotlib
Need a hint?

Just create a variable named hspace and assign it the value 0.5.

3
Adjust subplot spacing using plt.subplots_adjust()
Use plt.subplots_adjust() with the argument wspace=hspace to set the horizontal space between the subplots.
Matplotlib
Need a hint?

Call plt.subplots_adjust() and pass wspace=hspace to adjust horizontal spacing.

4
Display the figure
Use plt.show() to display the figure with the adjusted subplot spacing.
Matplotlib
Need a hint?

Call plt.show() to open the window showing your subplots.