【问题标题】:subplots from one figure to have the same dimensions as subplots from other figure一个图的子图与另一图的子图具有相同的尺寸
【发布时间】:2018-11-10 15:00:52
【问题描述】:

以下代码:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(ncols=3, nrows=4, sharex='col', sharey=False,\
            subplot_kw=dict(adjustable='box-forced'), figsize=(8, 8))

fig, axes = plt.subplots(ncols=3, nrows=3, sharex='col', sharey=False,\
            subplot_kw=dict(adjustable='box-forced'), figsize=(8, 8))    
plt.show()

产生两个图:

第一个图的子图分布为ncols=3, nrows=4。每个子图的大小都非常适合我的需要。

第二个情节的子情节分布为ncols=3, nrows=3

如何使这些子图中的每一个都具有与第一个图的子图相同的尺寸?

【问题讨论】:

    标签: matplotlib subplot axes


    【解决方案1】:

    一种方法是将最后一行设置为“不可见”:

    import matplotlib.pyplot as plt
    
    fig, axes = plt.subplots(ncols=3, nrows=4, sharex='col', sharey=False,\
                subplot_kw=dict(adjustable='box-forced'), figsize=(8, 8))
    
    fig, axes = plt.subplots(ncols=3, nrows=4, sharex='col', sharey=False,\
                subplot_kw=dict(adjustable='box-forced'), figsize=(8, 8))
    
    [ax.set_visible(False) for ax in axes[3,:]]
    plt.show()
    

    【讨论】:

    • 欢迎您快乐编码。我也认为,如果这不能满足您的需求,您可以使用 gridspec 执行此操作。
    • mmm...不确定gridspec 将如何控制子图的尺寸 - 从我无知的角度来看,我认为它更适合子图的位置
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多