Home > Software engineering >  Matplotlib - Change the white space between specific subplots in a grid grid
Matplotlib - Change the white space between specific subplots in a grid grid

Time:09-28

I have a grid of subplots and I would like to adjust the white space between only two of them such that the shared x labels are centred without overlapping either graph.

enter image description here

If I apply the solution to the linked question here then every subplot's white space is effected. I know this is because it calls on fig.dpi_scale_trans which effects the whole figure but I'm new to transforms and can't work out what to use in its place

In [2]
fig.tight_layout()
fig.subplots_adjust(wspace=0.7)

plt.setp(axes[0].yaxis.get_majorticklabels(), ha='center')

# Create offset transform by some points in x direction
dx = 60 / 72.
dy = 0 / 72.
offset = mlb.transforms.ScaledTranslation(dx, dy, fig.dpi_scale_trans)
# apply offset transform to all y ticklabels.
for label in ax6.yaxis.get_majorticklabels():
    label.set_transform(label.get_transform()   offset)

Out [2]

enter image description here

CodePudding user response:

I figured out how to solve this so posting my own answer in case anybody has a similar problem in the future.

enter image description here

  • Related