我试图使用底图生成一些地理 Map 的子图 . 这是我正在处理的代码部分:

import matplotlib.pyplot as plt
#---Some code to read in the data
# ...

#-----Get a A4 sized landscape figure
fig=plt.figure(figsize=(11.69,8.27), dpi=100)

#----2*3 Subplots-------------
for ii in range(6):
    ax=fig.add_subplot(2,3,ii+1)

    #---Basemap contourf of data
    baseIsofill(var[ii],ax,'local')
    ax.set_title('(a)',loc='left')


#plt.tight_layout()
plt.tight_layout(pad=2.0,h_pad=6.5,w_pad=4.5)
plt.show()

问题是子图布局:

  • 没有 tight_layout() ,子图中的图和文本赢得了't overlap, but they all ended up too small and don' t充分利用了图形空间(图1) .

  • 使用 plt.tight_layout() 时,子图占据了大部分可用的图形空间,但是纬度标签开始重叠(图2) .

  • plt.tight_layout(pad=2.0,h_pad=6.5,w_pad=4.5) 给出了期望的结果(图3) . 但是当使用不同的子图布局时需要改变参数(例如,横向A4上的3 * 2,图4,再次太小) .

2x3 subplots without tight_layout(), too small

2x3 subplots with tight_layout(), overlaps

2x3 subplots with tight_layout((pad=2.0,h_pad=6.5,w_pad=4.5), desired result

3x2 subplots with same tight_layout(pad=2.0,h_pad=6.5,w_pad=4.5) as in Fig.3, too small again

BaseIsofill() 函数中,我缩小了试图避免重叠的纬度标签的字体大小 . 缩小是子图布局的函数(fontsize = 7. / max(nrows,ncolns)5) . 除此之外,函数内部不会进行任何与大小相关的更改 .

如果我花时间调整填充参数,我总能得到一个好的结果,但这将涉及一些试验和错误测试,并不健壮 . 毕竟,对子图布局提供快速而强大的修复是 tight_layout 的意思 . 所以我想知道有没有人想出解决方案呢?

PS:我的matplotlib版本是1.3.1 . 底图版本是1.0.7