Skip to content Skip to sidebar Skip to footer

How To Adjust Different Margins Between Subplots

I want to adjust the margin between subplots using matplotlib. For example, I have three subplots, 3 rows * 1 column. I want hspace between ax0 and ax1 to be 0, and hspace between

Solution 1:

The hspace argument acts globally on all subplots. To have different hspaces, you may introduce another invisible plot in between the two bottom plots and adjust its height ratio to half of that of the others.

import matplotlib.pyplot as plt

fig, axes = plt.subplots(nrows=4,
                         gridspec_kw={"height_ratios" : [1,1,.5,1], "hspace":0})

axes[0].tick_params(axis="x", bottom=False, labelbottom=False)
axes[2].axis("off")

plt.show()

enter image description here


Post a Comment for "How To Adjust Different Margins Between Subplots"