Can't save full image with fig.subplots_adjust()

Hello everyone!
I’m try to create 3 y axis image reference the example " Multiple Yaxis With Spines".
But when I save the image, the image was not full.
I find fig.subplots_adjust(right=1.2) was the reason. If the right too big, the image was not full.
But the right less than 1.2, my y axis label will be overlapping.
How can I stay right=1.2 and get full image?

Here is my code:

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

# my data
groupA = ['A1','A2','A3','A4']
groupA_g = [
    0.000,
    3297.149,
    816.400,
    4113.549]
groupA_mPa = [
    9.802,
    7.976,
    10.338,
    7.592]
groupA_mm = [
    0.066,
    0.038,
    0.066,
    0.038]

fig, ax = plt.subplots(figsize=(10,8))
fig.subplots_adjust(right=1.2)

ax.set_title('Group A Result Image')

twin1 = ax.twinx()
twin2 = ax.twinx()

twin2.spines.right.set_position(("axes", 1.1))

x_pos = np.arange(len(groupA))

color_bar = '#2878B5'
color_line1 = '#F8AC8C'
color_line2 = '#C82423'

ax.bar(x_pos, groupA_g, align='center',color=color_bar)

line1, = twin1.plot(x_pos,groupA_mPa, color=color_line1, label="Max Stress(mPa)")
line2, = twin2.plot(x_pos, groupA_mm, color=color_line2, label="Max Displacement(mm)")

ax.set_ylim(0,5000)
twin1.set_ylim(5, 15)
twin2.set_ylim(0, 0.1)

ax.set_xticks(x_pos)
ax.set_xticklabels(groupA)

ax.set_xlabel("Model Code")
ax.set_ylabel('Quality Change')
twin1.set_ylabel("Max Stress(mPa)")
twin2.set_ylabel("Max Displacement(mm)")

ax.yaxis.label.set_color(color_bar)
twin1.yaxis.label.set_color(color_line1)
twin2.yaxis.label.set_color(color_line2)

tkw = dict(size=10, width=1.5)
ax.tick_params(axis='x', **tkw)
ax.tick_params(axis='y', colors=color_bar, **tkw)
twin1.tick_params(axis='y', colors=color_line1, **tkw)
twin2.tick_params(axis='y', colors=color_line2, **tkw)

for i,j in zip(x_pos,groupA_g):
    ax.annotate(str(j), xy=(i,j), xytext=(0,5), textcoords='offset points')

for i,j in zip(x_pos,groupA_mPa):
    twin1.annotate(str(j), xy=(i,j), xytext=(0,-20), textcoords='offset points')

for i,j in zip(x_pos,groupA_mm):
    twin2.annotate(str(j), xy=(i,j), xytext=(0,10), textcoords='offset points')

ax.legend(handles=[line1, line2],loc='upper left')

fig.savefig('./Group A Result Image.png',dpi=300)

type or paste code here


Thanks for any help!

You want to adjust the subplot to be smaller, not larger.

I’m new here so I not sure, but I use fig, ax = plt.subplots(figsize=(10,6),constrained_layout=True) solved this problem.