PyqtGraph RemoveItem仅删除最后一行

时间:2019-04-18 12:16:01

标签: python plot pyqtgraph

我正在使用DAQ GUI。在收集测试数据时,用户可以在PlotWidgets之间进行选择以显示绘图。这是通过选择图形复选框来完成的。如果未选中该复选框,则该通道数据将不会显示在任何图形上。

问题是当我使用RemoveItem()或table1.clear()函数时,仅最后一行被删除。曲线的其余部分保持不变。

共享问题的有效部分。

class Ui_Dialog(object):
def setupUi(self, Dialog):
    Dialog.setObjectName("Dialog")
    Dialog.resize(838, 688)
    self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
    self.buttonBox.setGeometry(QtCore.QRect(470, 640, 341, 32))
    self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
    self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
    self.buttonBox.setObjectName("buttonBox")

    font = QtGui.QFont()
    font.setPointSize(10)
    Dialog.setFont(font)


    self.pushButton=QtWidgets.QPushButton(Dialog)
    self.buttonBox.setGeometry(QtCore.QRect(600, 1000, 50, 32))
    self.pushButton.setFont(font)
    self.pushButton.setText("remove line")
    self.pushButton.setObjectName("pushButton_3")



    pg.setConfigOption('background', 'w')
    self.graphicsView = pg.PlotWidget(parent=Dialog)
    self.graphicsView.showGrid(x=True,y=True)
    self.graphicsView.setGeometry(QtCore.QRect(170, 140, 541, 321))
    pg.getConfigOption('foreground')
    self.graphicsView.setLabel('left', 'Temperature', 'C')
    self.graphicsView.setLabel('bottom', 'Time', 's')

    self.graphicsView.setObjectName("graphicsView")
    self.graphicsView.enableAutoRange(enable=True)
    self.graphicsView.setXRange(0,20,padding=0)        
    self.retranslateUi(Dialog)
    self.buttonBox.accepted.connect(Dialog.accept)
    self.buttonBox.accepted.connect(Dialog.reject)
    self.pushButton.clicked.connect(self.removeline)
    QtCore.QMetaObject.connectSlotsByName(Dialog)


def removeline(self):

    try: 
        self.graphicsView.plotItem.removeItem(table1)   

    except Exception as e:
        print(str(e))

def callfunc(self,val):

     process_delta=time.time()-val
     t=threading.Timer(1-process_delta,Ui_Dialog.update,args=(self,))
     t.daemon=True
     t.start()

def update(self):
    global count
    global table1
    table1=None
    process_start=time.time() 
    vals=int(time.time()-start)
    x_t.append(vals)
    y.append(count+1)

    pen = pg.mkPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine)

    table1=self.graphicsView.plot(x_t,y,pen=pen)
    QtCore.QCoreApplication.processEvents()

    count += 1
    self.callfunc(process_start)


def retranslateUi(self, Dialog):
    _translate = QtCore.QCoreApplication.translate
    Dialog.setWindowTitle(_translate("Dialog", "Dialog"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    start=time.time()
    Dialog.show()
    count=0
    x_t=[]
    y=[]
    vals=[]
    ui.update()
    sys.exit(app.exec_())

0 个答案:

没有答案