【问题标题】:How to set a layout once a matplotlib Figure has been created and what are the possible choices?创建 matplotlib 图后如何设置布局?可能的选择有哪些?
【发布时间】:2022-11-22 18:26:10
【问题描述】:

假设我创建了一个数字

from matplotlib import pyplot as plt
fig = plt.figure()

然后在我创建之后我想改变它布局(我知道我可以实例化数字通过传递参数对象布局plt.图,例如fig = plt.figure(layout="constrained"),这不是我想要的)。

到目前为止,我知道一个人可以做

fig.tight_layout()

设置一个紧凑的布局,但是如果设置一个“约束”布局?

此外,除了“紧的”“约束”其他可能的可用布局是什么?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您可以将 fig.set_layout_engine()matplolib-3.6.2 一起使用:

    如下:

    fig = plt.figure()
    fig.set_layout_engine('constrained')
    

    根据文档可能的布局是:'constrained', 'compressed', 'tight'

    【讨论】:

      猜你喜欢
      • 2016-01-23
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 2012-02-14
      • 2012-02-18
      • 1970-01-01
      相关资源
      最近更新 更多