我正在尝试在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)
这段代码生成了以下图形:
我尝试使用选项constrained_layout=True,以及fig.set_constrained_layout_pads,但它没有解决我的问题。
我知道可以使用supxlabel和supylabel的x、y、va和ha选项来解决问题,但我有很多要生成的图形,无法实际手动查找和设置这些选项的值。