0

I am trying to plot multiple data streams on a single plot using PyQt5. When I use setData, only the fifth column of the data stream is shown, i.e, I only see data_out[:,4] and not other columns. How do I implement a hold on instance of MATLAB in PyQt5?

class App(QMainWindow):

    def __init__(self):

        # initUI
        self.initUI()

        # define plots axis and labels
        self.pc1 = pg.PlotDataItem(name="ACC")
        self.pw1.addItem(self.pc1)
        self.pw1.setLabel('left', 'LEFT FOOT ACC', units='m/s^2')
        self.pw1.setLabel('bottom', 'Time', units='s')

        # timer
        self.timer = pg.QtCore.QTimer()

    def initUI(self):

        # create subplot grid
        self.pw1 = pg.PlotWidget()
        grid_layout.addWidget(self.pw1,2,0,1,4)

        # create start/stop button
        self.on_start = QPushButton("START")
        self.on_stop = QPushButton("STOP")
        grid_layout.addWidget(self.on_start,4,0,1,8)
        grid_layout.addWidget(self.on_stop,5,0,1,8)

    def on_start_clicked(self):
        # do something
        if not self.timer.isActive():
            self.timer.timeout.connect(self.updateplot)
            self.timer.start(8)


    def on_stop_clicked(self):
        # do something

    def updateplot(self):
        while (self.lcom.loop is True) and (not self.l_queue.empty()):

            self.data_out.append(self.l_queue.get())
            self.time_out.append(self.t)
            if len(self.data_out) != 0:
                self.pc1.setData(np.array(self.data_out)[:,2],pen=(255,0,0))
                self.pc1.setData(np.array(self.data_out)[:,3],pen=(0,255,0))
                self.pc1.setData(np.array(self.data_out)[:,4],pen=(0,0,255))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())
Maxtron
  • 272
  • 1
  • 2
  • 15
  • There a solution in the link below, but that's for `pyqtgraph` and not `plotWidget()`. https://stackoverflow.com/questions/40577104/how-to-plot-two-real-time-data-in-one-single-plot-in-pyqtgraph – Maxtron Dec 02 '18 at 03:19
  • It is the same but it seems that you have not understood the solution, for your case I have created your next solution: https://gist.github.com/eyllanesc/1980606ba040013b847a96f8cdb6af02 – eyllanesc Dec 02 '18 at 03:28
  • in `p1 = win.addPlot()` p1 is a plotWidget. – eyllanesc Dec 02 '18 at 03:30
  • Thanks, @eyllanesc. I looked at your solution on github and realized I need to create new instances every time a new plot appears. I appreciate your quick and prompt response :) – Maxtron Dec 02 '18 at 03:31

0 Answers0