【发布时间】:2023-02-16 23:01:38
【问题描述】:
我试图在 matplotlib 的子图中添加一个公共标签,但我遇到了一些麻烦。
我正在使用 python 3.10 和 matplotlib 3.5.1
有一个最小的工作示例说明了这个问题:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(3, 2, figsize=(8, 12), sharex=True, sharey=True)
fig.supxlabel('Example of supxlabel')
fig.supylabel('Example of supylabel')
fig.subplots_adjust(wspace=0, hspace=0)
plt.savefig('test.pdf', bbox_inches='tight', pad_inches=0)
此代码生成下图:
请注意'Example of supxlabel' 和'Example of supylabel' 上方巨大的丑陋边距。
我尝试使用选项 constrained_layout=True 和 fig.set_constrained_layout_pads,但它没有解决我的问题。
我知道可以使用x、y、va和ha中的supxlabel和supylabel来解决问题,但我有很多数字要生成,无法实际找到和设置值这些选项手动。
【问题讨论】:
-
尝试 plt.tight_layout(),您可以检查可以自动改变不同垫的选项
标签: python matplotlib