Matplotlib subplots_adjust for Bottom and Right Margins

When I was working on a data visualization project for a client in the USA, I had to prepare multiple charts for a business dashboard. The issue was that the axis labels and titles were getting cut off because the margins at the bottom and right side were too tight.

That’s where the subplots_adjust() function comes in handy. With this function, I can easily control the spacing around my plots, including the bottom and right margins.

In this tutorial, I will show you how I use Matplotlib subplots_adjust to fix bottom and right margins in Python. I will cover multiple methods, share full code examples, and explain each step in simple words.

What is subplots_adjust in Matplotlib?

The subplots_adjust() function in Matplotlib allows me to manually adjust the spacing between subplots and the edges of the figure.

It is especially useful when I want to prevent overlapping text, cut-off labels, or when I need extra space for legends and annotations.

The function takes several parameters, but the most relevant ones for this tutorial are:

  • bottom: Adjusts the space from the bottom of the figure.
  • right: Adjusts the space from the right side of the figure.

By changing these parameters, I can control how much room is available for elements like x-axis labels or legends.

Method 1 – Adjust Bottom Margin with subplots_adjust in Python

When I add long x-axis labels in Python, they often overlap or get cut off. To fix this, I increase the bottom margin using subplots_adjust(bottom=).

Here is a simple example.

import matplotlib.pyplot as plt

# Sample data for US states population in millions
states = ['California', 'Texas', 'Florida', 'New York']
population = [39.24, 29.53, 21.78, 19.84]

# Create a bar chart
plt.bar(states, population, color='skyblue')

# Set title and labels
plt.title("Population of Top US States")
plt.xlabel("States")
plt.ylabel("Population (Millions)")

# Adjust bottom margin
plt.subplots_adjust(bottom=0.25)

# Show plot
plt.show()

You can refer to the screenshot below to see the output.

Matplotlib subplots_adjust for Bottom and Right Margins

In this Python example, I used bottom=0.25 to add more space at the bottom. Now the state names are clearly visible without overlapping, making the chart more professional.

Method 2 – Adjust Right Margin with subplots_adjust in Python

Sometimes, legends or annotations are placed on the right side of the chart and get cut off. In those cases, I increase the right margin using subplots_adjust(right=).

Here’s how I do it.

import matplotlib.pyplot as plt

# Sample data for US industries revenue in billions
industries = ['Tech', 'Healthcare', 'Finance', 'Retail']
revenue = [1200, 950, 1100, 870]

# Create a pie chart
plt.pie(revenue, labels=industries, autopct='%1.1f%%')

# Add a title
plt.title("Revenue Distribution by US Industries")

# Place legend outside the plot
plt.legend(industries, loc="center left", bbox_to_anchor=(1, 0.5))

# Adjust right margin to make space for legend
plt.subplots_adjust(right=0.8)

# Show plot
plt.show()

You can refer to the screenshot below to see the output.

subplots_adjust for Bottom and Right Margins in Matplotlib

In this Python code, I set right=0.8 to create extra space for the legend on the right side. This way, the legend is fully visible and does not overlap with the pie chart.

Method 3 – Adjust Both Bottom and Right Margins Together

In real-world projects, I often need to adjust both bottom and right margins at the same time. This is especially true when I have long x-axis labels and legends outside the chart.

Here is an example where I handle both margins.

import matplotlib.pyplot as plt

# Sample data for US city average monthly rent in dollars
cities = ['New York', 'Los Angeles', 'Chicago', 'Houston']
rent = [3500, 2800, 2200, 1800]

# Create a bar chart
plt.bar(cities, rent, color='orange')

# Add labels and title
plt.title("Average Monthly Rent in Major US Cities")
plt.xlabel("City")
plt.ylabel("Rent (USD)")

# Add a legend outside
plt.legend(["Rent"], loc="center left", bbox_to_anchor=(1, 0.5))

# Adjust both bottom and right margins
plt.subplots_adjust(bottom=0.25, right=0.8)

# Show plot
plt.show()

You can refer to the screenshot below to see the output.

Matplotlib subplots_adjust for Bottom, Right Margins

In this Python example, I increased both bottom and right margins. This ensures the city names at the bottom are readable and the legend on the right is not cut off.

Method 4 – Use subplots_adjust with Multiple Subplots

When I work with multiple subplots in Python, spacing issues are even more common. In such cases, I use subplots_adjust() to control bottom and right margins for the entire figure.

Here’s a practical example.

import matplotlib.pyplot as plt

# Sample data for US GDP growth and unemployment rate
years = [2018, 2019, 2020, 2021, 2022]
gdp_growth = [2.9, 2.3, -3.4, 5.7, 2.1]
unemployment = [3.9, 3.7, 8.1, 5.4, 3.6]

# Create subplots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))

# Plot GDP growth
ax1.plot(years, gdp_growth, marker='o', color='green')
ax1.set_title("US GDP Growth (%)")
ax1.set_xlabel("Year")
ax1.set_ylabel("Growth Rate")

# Plot Unemployment rate
ax2.plot(years, unemployment, marker='s', color='red')
ax2.set_title("US Unemployment Rate (%)")
ax2.set_xlabel("Year")
ax2.set_ylabel("Rate")

# Adjust margins for both subplots
plt.subplots_adjust(bottom=0.2, right=0.85)

# Show plot
plt.show()

You can refer to the screenshot below to see the output.

subplots_adjust for Bottom, Right Margins in Matplotlib

In this Python example, I adjusted the margins so both plots fit nicely without cutting off labels. This makes the figure presentation-ready for reports or business dashboards.

Method 5 – Combine subplots_adjust with tight_layout

Sometimes, I use tight_layout() along with subplots_adjust() for even better control. The tight_layout() function automatically adjusts spacing, but I can still fine-tune the bottom and right margins with subplots_adjust().

import matplotlib.pyplot as plt

# Sample data for average gas prices in the USA
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']
prices = [3.1, 3.2, 3.4, 3.6, 3.5]

# Create a line chart
plt.plot(months, prices, marker='o', color='blue')

# Add title and labels
plt.title("Average Gas Prices in the USA (2025)")
plt.xlabel("Month")
plt.ylabel("Price (USD per Gallon)")

# Apply tight layout first
plt.tight_layout()

# Fine-tune bottom and right margins
plt.subplots_adjust(bottom=0.2, right=0.9)

# Show plot
plt.show()

In this Python code, I first applied tight_layout() and then used subplots_adjust() for fine-tuning. This approach gives me the best of both worlds: automatic spacing plus manual control.

Using Matplotlib subplots_adjust in Python has saved me countless hours of frustration when preparing charts.

Whether I am working on business reports, data analysis for clients in the USA, or academic projects, controlling the bottom and right margins makes my visualizations look polished and professional.

If you often struggle with cut-off labels or legends, I recommend experimenting with subplots_adjust(bottom=, right=). You’ll quickly see how much cleaner your plots look.

You may also like to read the given Matplotlib articles:

Leave a Comment

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.