我在 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,在 1 和 2 之间为 x,在 2 和 3 之间为 0?
谢谢。
最佳答案
是的,如果您按照文档中的说明使用 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()
还没有能够测试它,所以希望它有效。
关于python - 分离一些子图而不是其他的; Python,Matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28984757/