如何设置matplotlib图形的边距? [英] How to set the margins for a matplotlib figure?

查看:2184
本文介绍了如何设置matplotlib图形的边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一个包含两个子图的屏幕图形:一个是图像,另一个是图形.这些数字的边距非常大.

I am generating an on-screen figure that has two subplots: one is an image and the other is a graph. The margins are extremely large around the figures.

如何调整数字的边距?

我搜索的大多数问题都涉及保存图像(bbox看起来很完美),并且使用轴而不是子图进行绝对定位.

Most questions that I searched for involved saving images (bbox seemed perfect), and using axes instead of subplots for absolute positioning.

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

Here is the code I used to generate the figure:

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').

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

With subplots_adjust you can adjust most parameters, while tight_layout() and bbox_inches='tight' are more or less semi automatic.

这篇关于如何设置matplotlib图形的边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆