When I first started working with Python data visualization, one of the biggest challenges I faced was managing subplots.
I often had multiple charts side by side, and each had its own axis labels. This looked messy and confusing, especially when I wanted to compare trends between charts. I discovered that Matplotlib makes it easy to share axis and axis labels across subplots. This not only saves space but also makes charts cleaner and easier to read.
In this tutorial, I’ll show you exactly how to share axis and axis labels in Matplotlib subplots. I’ll walk you through practical Python examples, explain the methods step by step, and share tips I’ve learned.
Share Axis and Axis Labels in Matplotlib
When you create multiple subplots in Python using Matplotlib, each subplot comes with its own x-axis and y-axis.
This is fine for small projects, but if you’re building dashboards or comparing data across multiple plots, repeated axis labels can clutter your visualization.
By sharing axes and labels, you can:
- Save space in your figure.
- Make comparisons easier for the viewer.
- Create professional-looking charts for reports or dashboards.
Now let’s dive into the methods.
Share Axis in Matplotlib Subplots
Sharing axes in Matplotlib means that all subplots use the same scale for either x-axis, y-axis, or both.
This is especially useful when you’re comparing datasets that are measured on the same scale.
Method 1 – Share X-Axis Across Subplots
When I want to compare time-series data, I usually share the x-axis. This way, all subplots align perfectly on the time scale.
Here’s a Python example:
import matplotlib.pyplot as plt
import numpy as np
# Sample data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
# Create subplots with shared x-axis
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(8, 6))
ax1.plot(x, y1, color='blue')
ax1.set_title("Sine Wave")
ax2.plot(x, y2, color='red')
ax2.set_title("Cosine Wave")
# Add overall x-axis label
plt.xlabel("Time (seconds)")
plt.tight_layout()
plt.show()I executed the above example code and added the screenshot below.

This code creates two subplots stacked vertically. Both share the same x-axis, so the time scale is consistent.
Method 2 – Share Y-Axis Across Subplots
Sometimes I want to compare values across categories, so I share the y-axis instead.
Here’s how I do it in Python:
import matplotlib.pyplot as plt
import numpy as np
# Sample data
categories = ["NY", "CA", "TX", "FL", "IL"]
values1 = [20, 35, 30, 35, 27]
values2 = [25, 32, 34, 20, 25]
# Create subplots with shared y-axis
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(10, 5))
ax1.bar(categories, values1, color='green')
ax1.set_title("2024 Sales Data")
ax2.bar(categories, values2, color='orange')
ax2.set_title("2025 Sales Data")
# Add overall y-axis label
fig.text(0.04, 0.5, "Sales (in thousands)", va="center", rotation="vertical")
plt.tight_layout()
plt.show()I executed the above example code and added the screenshot below.

Here, both bar charts share the same y-axis. This makes it clear that we’re comparing sales across states without repeating the axis labels.
Method 3 – Share Both X and Y Axes
When I’m working with multiple plots that use the same scale for both dimensions, I share both axes.
Here’s a Python snippet:
import matplotlib.pyplot as plt
import numpy as np
# Sample data
x = np.random.randn(100)
y = np.random.randn(100)
# Create subplots with shared x and y axes
fig, axes = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(8, 8))
axes[0, 0].scatter(x, y, color='blue')
axes[0, 0].set_title("Plot 1")
axes[0, 1].scatter(x, y*2, color='red')
axes[0, 1].set_title("Plot 2")
axes[1, 0].scatter(x*2, y, color='green')
axes[1, 0].set_title("Plot 3")
axes[1, 1].scatter(x*3, y*3, color='purple')
axes[1, 1].set_title("Plot 4")
plt.suptitle("Shared Axes Example", fontsize=14)
plt.tight_layout()
plt.show()In this case, all four scatter plots share both axes. This makes it easy to compare distributions side by side.
Share Axis Labels in Matplotlib Subplots
Sharing axis labels is slightly different from sharing axes. Instead of each subplot having its own axis label, you can create one common label for the entire figure.
This is very useful when you want to avoid duplicate labels and make your chart look cleaner.
Method 1 – Use plt.xlabel() and plt.ylabel() in Python
When I want to add a single label for the x-axis or y-axis, I often use plt.xlabel() and plt.ylabel().
Here’s a Python example:
import matplotlib.pyplot as plt
import numpy as np
# Sample data
x = np.linspace(0, 5, 50)
y1 = np.exp(x)
y2 = np.log(x + 1)
# Create subplots with shared x-axis
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(8, 6))
ax1.plot(x, y1, color="blue")
ax1.set_title("Exponential Growth")
ax2.plot(x, y2, color="red")
ax2.set_title("Logarithmic Growth")
# Add shared axis labels
plt.xlabel("X-Axis (Input)")
plt.ylabel("Y-Axis (Output)")
plt.tight_layout()
plt.show()I executed the above example code and added the screenshot below.

This method is quick and works well if you’re stacking subplots vertically or horizontally.
Method 2 – Use Python’s fig.text() for More Control
For more flexibility, I use fig.text() to place axis labels anywhere in the figure.
Here’s how:
import matplotlib.pyplot as plt
import numpy as np
# Sample data
x = np.arange(1, 6)
y1 = [2, 4, 6, 8, 10]
y2 = [1, 3, 5, 7, 9]
# Create subplots
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(10, 5))
ax1.plot(x, y1, marker="o")
ax1.set_title("Dataset 1")
ax2.plot(x, y2, marker="s")
ax2.set_title("Dataset 2")
# Add shared labels
fig.text(0.5, 0.04, "X-Axis (Categories)", ha="center")
fig.text(0.04, 0.5, "Y-Axis (Values)", va="center", rotation="vertical")
plt.tight_layout()
plt.show()I executed the above example code and added the screenshot below.

This approach gives me precise control over where the labels appear, which is very useful when building dashboards.
Method 3 – Use Python’s fig.supxlabel() and fig.supylabel() (Python 3.4+)
In newer versions of Matplotlib, I can use fig.supxlabel() and fig.supylabel() to add shared labels directly.
Here’s an example:
import matplotlib.pyplot as plt
import numpy as np
# Sample data
x = np.linspace(0, 2*np.pi, 100)
y1 = np.sin(x)
y2 = np.cos(x)
# Create subplots
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(8, 6))
ax1.plot(x, y1, color="blue")
ax1.set_title("Sine Function")
ax2.plot(x, y2, color="green")
ax2.set_title("Cosine Function")
# Add shared labels
fig.supxlabel("Angle (radians)")
fig.supylabel("Function Value")
plt.tight_layout()
plt.show()This is my favorite method because it’s clean and requires less manual adjustment.
Sharing axes and axis labels in Matplotlib is a powerful way to make your Python visualizations more professional.
When I first learned this, it completely changed how I built dashboards and reports. My charts became cleaner, easier to compare, and much more presentation-ready.
If you’re working with subplots in Python, I strongly recommend trying these methods. Start with simple sharex or sharey, then experiment with fig.supxlabel() and fig.supylabel() for shared labels.
With a little practice, you’ll find yourself creating charts that are not only functional but also visually appealing.
You may also read other tutorials:
- Matplotlib Subplot Figure Size in Python
- Set Titles for Each Subplot and Overall Title in Matplotlib
- Matplotlib Subplot Titles – Change Font Size and Bold Text
- Matplotlib Subplot Title Style – Change Position and Padding

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.