分离一些子图而不是其他子图; Python,Matplotlib

时间:2015-03-11 10:56:35

标签: python python-2.7 matplotlib 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)

当我更改wspace时,我会得到4列相等的间距。有没有办法改变wspace,使得0和1列之间为0,x介于1和2之间,0介于2和3之间?

感谢。

1 个答案:

答案 0 :(得分:3)

是的,如果您使用文档中所述的GridSpec,则可以:Adjust GridSpec layout

修改

示例代码,从上面的例子中修改,它应该是什么样子:

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()

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