简体   繁体   中英

Matplotlib in PyQt5: How to remove the small space along the edge

I have a matplotlib.pyplot object inside a QVBoxLayout in PyQt5 widget . There are small spaces along the edge which is really annoying. How do I remove it?

See the screensnap below. I already tried setlayoutSpacing(0) , which have no effect.

在此处输入图片说明

Here is the breviate code (Cutout many data processing codes):

class MpWidget_SCF(Qt.QWidget):
    def __init__(self, parent=None, y=[]):
        super(MpWidget_SCF, self).__init__()
        self.setParent(parent)

        self.dpi = 50
        self.fig = MpPyplot.figure(figsize=(2, 2), dpi=self.dpi, )
        self.SCF_subplot = MpPyplot.subplot(1, 1, 1)

        self.canvas = MpFigureCanvas(self.fig)
        self.canvas.setParent(self)
        self.SCF_subplot.clear()
        self.SCF_subplot.plot(range(len(y)), y, 'r')
        self.canvas.draw()

        self.vLayout = Qt.QVBoxLayout()
        self.vLayout.addWidget(self.canvas)
        self.vLayout.setSpacing(0)
        self.setLayout(self.vLayout)

class myWidget(Qt.QWidget):
    def __init__(self):
        super(myWidget, self).__init__()
        self.main = Ui_OutputWindow_Form()
        self.main.setupUi(self)

        self.main.SCF_Graphic_Widget = MpWidget_SCF(self)
        self.main.verticalLayout_2.addWidget(self.main.SCF_Graphic_Widget)

        self.show()

您可以删除默认边距

    self.vLayout.setContentsMargins(0, 0, 0, 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM