PyQt5中的Matplotlib:如何删除沿edg的小空间

2024-06-27 02:04:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我在PyQt5widget中的QVBoxLayout中有一个matplotlib.pyplot对象。沿边缘有一些很小的空间,真的很烦人。如何删除它?在

请参见下面的屏幕截图。 我已经试过setlayoutSpacing(0),但没有效果。在

enter image description here

下面是breviate代码(删去许多数据处理代码):

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()

Tags: 代码selfinitmaindefqtclasscanvas