18

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

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


我搜索的大多数问题都涉及保存图像(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)
4

2 回答 2

26

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

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

于 2012-06-07T07:03:37.273 回答
-3

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

于 2013-02-18T14:23:09.923 回答