如何调整子图之间的不同边距

时间:2017-06-24 07:57:27

标签: python matplotlib

我想使用matplotlib调整子图之间的边距。例如,我有三个子图,3行* 1列。我希望ax0和ax1之间的hspace为0,并且ax1和ax2之间的hspace为0.5 使用plt.subplots_adjust(hspace=0)会将hspace调整为相同,但我希望它们不同。我们怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

hspace参数在所有子图上全局操作。要拥有不同的hspace,您可以在两个底部图之间引入另一个不可见的图,并将其高度比调整为其他图的一半。

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

相关问题