【问题标题】:Separating some subplots but not others; Python, Matplotlib分离一些子图而不是其他子图; Python, Matplotlib
【发布时间】:2015-05-13 03:11:09
【问题描述】:

我正在 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?

谢谢。

【问题讨论】:

    标签: python python-2.7 matplotlib subplot


    【解决方案1】:

    是的,如果您使用 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()
    

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

    【讨论】:

    • 请避免仅提供链接的答案,因为链接可能会更改、损坏或链接的内容会在 SO 的控制之外进行更新。
    • 刚刚试了一下,效果很好。感谢您的示例,我无法掌握链接中的信息。
    猜你喜欢
    • 2015-10-24
    • 2021-12-28
    • 2018-05-14
    • 1970-01-01
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多