0
votes

I have included in my MainWidget class the PlotWidget to realtime show data coming from a serial communication:

MyApp

The start button simply plot what arrives, but i would like to clear the view every time I push start. Instead (as you can see in the picture) the plot still show the previous plot and simply overwrite.

The clear() method does not do nothing I tried everything to rid out the past plot, for example every time I call start I tried to do this:

def Start(self):
    if self.SampleLine.text():
        self.StartButton.setEnabled(0)

        self.plot1 = self.Chart.plot([], [], name='Signal', pen=pg.mkPen(color='g'))
        self.plot2 = self.Chart.plot([], [], name='Threshold', pen=pg.mkPen(color='r'))
        self.plot1.clear()
        self.plot2.clear()
        self.plot1.setData([0], [0])
        self.plot2.setData([0], [0])
        QApplication.processEvents()
        self.Chart.removeItem(self.plot1)
        self.Chart.removeItem(self.plot2)
        QApplication.processEvents()
        self.Chart.addItem(self.plot1)
        self.Chart.addItem(self.plot2)
        QApplication.processEvents()

Simply tried to create new plot, remove items etc etc.. but the older plot remains in the view