如何为matplotlib图形设置边距?

19
我正在生成一个屏幕上的图形,其中包含两个子图:一个是图像,另一个是图表。图形周围的边距非常大。
如何调整图形周围的边距?
大多数我搜索到的问题都涉及保存图像(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)

1
许多函数仅适用于Pylab模式和保存图形。我想要适用于“Figure”对象的东西。 - Jesvin Jose
2个回答

28
请查看plt.tight_layout()plt.subplots_adjust() 或者 fig.savefig(bbox_inches='tight')

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


-3

您还可以使用plt.set(),其中包含在调整绘图菜单中给定的属性,例如set(top=0.82)等。


我在文档http://matplotlib.org/api/pyplot_api.html中没有找到matplotlib.pyplot.set。 - usernumber
他们可能在过去的两年中更改了他们的API。 - Tritlo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接