How to customize different margins between subheadings

I want to adjust the border between subplots using matplotlib. For example, I have three subheadings, 3 rows * 1 columns. I want the hspace between ax0 and ax1 to be 0 and the hspace between ax1 and ax2 to be 0.5.
Use plt.subplots_adjust(hspace=0)

to set hspaces to be the same, but I want them to be different. How can we achieve this?

+3


source to share


1 answer


The argument hspace

is valid globally in all subplots. To have different hspaces, you can introduce another invisible plot between the two bottom plots and adjust its height ratio to half the rest.

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

+2


source







All Articles