I’ve worked extensively with data visualization. One library that has always been a go-to is Matplotlib. It’s useful, flexible, and widely used across industries, especially here in the USA, where data-driven decisions are the norm.
One feature I often rely on is subplots. They allow you to display multiple plots in a single figure, making it easier to compare data side-by-side.
In this tutorial, I’ll walk you through how to create, customize, and manage Matplotlib subplots effectively. I’ll share practical tips from my experience to help you build clear and insightful visualizations.
What Are Matplotlib Subplots?
Subplots are individual plots positioned within a single figure window. Instead of opening multiple windows for each chart, subplots let you organize multiple plots in a grid layout.
This is especially useful when comparing datasets, for example, visualizing unemployment rates across different US regions or comparing monthly sales figures for multiple stores.
Create Subplots Using plt.subplot()
The simplest way to create subplots is using the plt.subplot() function in Python. It divides the figure into a grid and selects the active subplot.
Here’s a quick example:
import matplotlib.pyplot as plt
# Create a 2x2 grid of subplots
plt.figure(figsize=(10, 8))
plt.subplot(2, 2, 1)
plt.plot([1, 3, 5], [10, 20, 30])
plt.title('Plot 1')
plt.subplot(2, 2, 2)
plt.plot([1, 3, 5], [30, 20, 10])
plt.title('Plot 2')
plt.subplot(2, 2, 3)
plt.bar(['NY', 'CA', 'TX'], [100, 200, 150])
plt.title('Sales by State')
plt.subplot(2, 2, 4)
plt.scatter([5, 7, 8], [2, 3, 5])
plt.title('Random Scatter')
plt.tight_layout()
plt.show()You can see the output in the screenshot below.

Using plt.subplot() is easy and quick for simple layouts. It’s perfect when you want to create a few plots fast without much customization.
Read Matplotlib Not Showing Plot
Use plt.subplots() for More Control
For more flexibility, I prefer plt.subplots(). It returns a figure and an array of axes objects, giving you more control over each subplot.
Example:
fig, axes = plt.subplots(2, 2, figsize=(10, 8))
axes[0, 0].plot([1, 2, 3], [3, 2, 1])
axes[0, 0].set_title('Line Plot')
axes[0, 1].bar(['NY', 'CA', 'TX'], [120, 150, 90])
axes[0, 1].set_title('Bar Chart')
axes[1, 0].hist([5, 7, 8, 5, 6, 7, 8])
axes[1, 0].set_title('Histogram')
axes[1, 1].scatter([1, 2, 3], [4, 5, 6])
axes[1, 1].set_title('Scatter Plot')
plt.tight_layout()
plt.show()You can see the output in the screenshot below.

My Experience with plt.subplots()
This method is my favorite because it makes it easy to loop through axes for bulk formatting or applying consistent styles. When working on dashboards or reports for clients, this approach saves me a lot of time.
Check out Matplotlib Multiple Plots
Share Axes for Cleaner Comparisons
When plotting related data, sharing axes between subplots helps maintain consistent scales and improves readability.
Here’s how to do it:
fig, axes = plt.subplots(2, 1, sharex=True, figsize=(8, 6))
axes[0].plot([1, 2, 3, 4], [10, 20, 25, 30])
axes[0].set_title('Quarterly Revenue')
axes[1].plot([1, 2, 3, 4], [15, 18, 20, 22])
axes[1].set_title('Quarterly Profit')
plt.xlabel('Quarter')
plt.tight_layout()
plt.show()You can see the output in the screenshot below.

Why Use Shared Axes?
Sharing the x-axis here means the quarters line up perfectly, making it easier to compare revenue and profit trends over time. I often use this when presenting financial data to stakeholders.
Read Matplotlib Legend Font Size
Adjust Spacing with plt.tight_layout() and fig.subplots_adjust()
Sometimes, subplot titles or labels overlap. I always use plt.tight_layout() to adjust spacing automatically.
For finer control, fig.subplots_adjust() lets you tweak margins manually:
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
for i, ax in enumerate(axes):
ax.plot([1, 2, 3], [i+1, i+2, i+3])
ax.set_title(f'Plot {i+1}')
fig.subplots_adjust(left=0.1, right=0.9, wspace=0.4)
plt.show()In my experience, these tools help keep your plots professional and easy to read, especially when preparing reports or presentations.
Read Matplotlib Secondary y-Axis
Create Complex Layouts with GridSpec
For more advanced layouts, GridSpec is a powerful tool. It allows you to create subplots of varying sizes and positions.
Example:
import matplotlib.gridspec as gridspec
fig = plt.figure(figsize=(8, 6))
gs = gridspec.GridSpec(3, 3)
ax1 = fig.add_subplot(gs[0, :])
ax1.plot([1, 2, 3], [3, 2, 1])
ax1.set_title('Wide Plot')
ax2 = fig.add_subplot(gs[1:, 0])
ax2.bar(['NY', 'CA', 'TX'], [100, 200, 150])
ax2.set_title('Tall Plot')
ax3 = fig.add_subplot(gs[1:, 1:])
ax3.scatter([1, 2, 3], [4, 5, 6])
ax3.set_title('Big Plot')
plt.tight_layout()
plt.show()I often use GridSpec when building dashboards that require a mix of large and small plots, like combining a map with detailed charts.
Add Titles and Labels to Subplots
To make your visualization clear, always label your axes and add titles.
You can do this individually for each subplot:
fig, axes = plt.subplots(1, 2, figsize=(10, 4))
axes[0].plot([1, 2, 3], [4, 5, 6])
axes[0].set_title('Sales Over Time')
axes[0].set_xlabel('Month')
axes[0].set_ylabel('Sales ($)')
axes[1].bar(['NY', 'CA', 'TX'], [150, 200, 180])
axes[1].set_title('Sales by State')
axes[1].set_xlabel('State')
axes[1].set_ylabel('Sales ($)')
plt.tight_layout()
plt.show()Clear labeling is something I never skip; it helps the audience understand the story behind the data immediately.
Check out Matplotlib Set Axis Range
Save Subplots as Images
Once your subplots look good, you can save them for reports or presentations.
Use:
plt.savefig('sales_dashboard.png', dpi=300)I recommend saving at 300 dpi for print-quality images, especially when sharing with clients or including in official documents.
Matplotlib subplots are a fundamental skill for any Python developer working with data visualization. Whether you’re comparing quarterly sales across US regions or analyzing multiple economic indicators, subplots help you tell your story clearly and effectively.
From simple plt.subplot() calls to advanced GridSpec layouts, there’s a method for every need. Use shared axes for better comparisons, tweak spacing for clarity, and always label your plots.
With these tools, you’ll create professional, insightful visualizations that make your data stand out.
Other Matplotlib articles you may also like:

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.