分离一些次要情节,但不分离其他次要情节;Python、Matplotlib

tho*_*hor 6 python matplotlib python-2.7 subplot

我正在 python (v 2.7.9) 中使用 matplotlib (v 1.4.2) 绘制子图网格。我可以手动调整子图之间的间距,但我希望仅某些子图具有不同的间距。我希望的最终图形是左侧有一个 2x5 子图网格,右侧有一个 2x5 子图网格,中间有一个空格。

我用来控制图形布局的代码如下:

figw, figh = 16.5, 15.0 #18.5, 15.0
fig, axes = plt.subplots(ncols=4, nrows=5, sharex=False, 
                         sharey=True, figsize=(figw, figh))

plt.subplots_adjust(hspace=0.0, wspace=0.2, left=1/figw,
                    right=1-2./figw, bottom=1/figh, top=1-2./figh)
Run Code Online (Sandbox Code Playgroud)

当我改变时wspace,我得到 4 列均等间距。有没有办法wspace以这样的方式进行更改:第 0 列和第 1 列之间为 0,第 1 列和第 2 列之间为 x,第 2 列和第 3 列之间为 0?

谢谢。

dei*_*aur 4

是的,如果您GridSpec按照文档中的描述使用,则可以:调整 GridSpec 布局

编辑:

根据上面的示例修改的示例代码,其外观应如下所示:

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

f = plt.figure()

plt.suptitle("Different vertical spacings")

gs1 = GridSpec(5, 2)
gs1.update(left=0.05, right=0.48, wspace=0)
ax1 = plt.subplot(gs1[0,0])
ax2 = plt.subplot(gs1[1, 0])
#Add the other subplots for left hand side

gs2 = GridSpec(5, 2)
gs2.update(left=0.55, right=0.98, wspace=0)
ax11 = plt.subplot(gs2[0,0])
ax12 = plt.subplot(gs2[1,0])
#Add the other subplots for right hand side

plt.show()
Run Code Online (Sandbox Code Playgroud)

无法测试它,所以希望它有效。