gpt4 book ai didi

python - PyQt5 中的 Matplotlib : How to remove the small space along the edge

转载 作者:太空宇宙 更新时间:2023-11-03 17:54:20 26 4
gpt4 key购买 nike

我在 PyQt5 widgetQVBoxLayout 内有一个 matplotlib.pyplot 对象。边缘有一些小空间,这真的很烦人。如何删除它?

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

enter image description here

这里是简要代码(删去了很多数据处理代码):

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

最佳答案

您可以删除 default margins :

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

关于python - PyQt5 中的 Matplotlib : How to remove the small space along the edge,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28700302/

26 4 0