【问题标题】:How to set the margins for a matplotlib figure?如何设置 matplotlib 图形的边距?
【发布时间】:2013-02-18 22:23:09
【问题描述】:

我正在生成一个具有两个子图的屏幕图形:一个是图像,另一个是图形。数字周围的边距非常大。

如何调整数字周围的边距?


我搜索的大多数问题都涉及保存图像(bbox 似乎很完美),以及使用轴而不是子图进行绝对定位。

这是我用来生成图形的代码:

def __init__(self, parent):
    wx.Panel.__init__(self, parent)
    ...

    self.figure, (self.picture, self.intensity) = \
        plt.subplots(nrows=2, figsize=(12, 5))
    self.figure.set_dpi(80)
    #self.figure.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
    #self.picture.imshow(np.random.uniform()) #size=(5, 50)))
    self.intensity.plot(np.random.random()) #size=641))

    self.intensity.autoscale(axis='x', tight=True)

【问题讨论】:

  • 看看 plt.tight_layout() 或 plt.subplots_adjust() 或 fig.savefig(bbox_inches='tight')
  • @bmu,我认为你的评论应该是一个答案,不是吗?
  • 许多功能仅适用于 Pylab 模式和保存图形。我想要适用于 Figure 对象的东西。
  • @Yann,好的,谢谢。或多或少有一些链接,但应该足以回答问题。

标签: python matplotlib


【解决方案1】:

看看plt.tight_layout()plt.subplots_adjust()fig.savefig(bbox_inches='tight')

使用subplots_adjust,您可以调整大多数参数,而tight_layout()bbox_inches='tight' 或多或少是半自动的。

【讨论】:

    【解决方案2】:

    您还可以使用 plt.set(),以及调整绘图菜单中给出的属性,例如设置(顶部=0.82)等。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    相关资源
    最近更新 更多