pyqtgraph: multi axis for live data stream tracking in multi(grid)plot

Viewed 7

My aim is to collect many pressure data from pressure sensors (about 25) and draw it as much as faster.

I create a 5x3 grid-plot to flow 15 of them, but for rest sensors I would like to create a multi axis graphs to save space and also flow related sensors in one common plotting area.

I already figured out this example for multi axis plotting with pyqtgraph; https://github.com/pyqtgraph/pyqtgraph/blob/develop/examples/MultiplePlotAxes.py, but there is many line code and I believe my algorithm knowledge is not enough to integrate it with my current code. Could you please show me how I can integrate multi-axis into my code, for example, if I would like at multi axis to first three plots; at 1x1, 1x2, 1x3? Or do know is there any easily way to adapt multi-axis on a grid type multi-plot graph with pyqtgraph library. I would like to stay with pyqtgraph because other visualization libraries are quite slow for this purpose.

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtWidgets
import numpy as np
import time

win = pg.GraphicsLayoutWidget(show=True)
win.setWindowTitle('pyqtgraph pressure tracking :)')
win.setGeometry(50, 50, 800, 700)

# define dimension of plot-grid
grid_row = 5
grid_col = 3
grid_num = grid_row * grid_col
layout_g = [[], ] * grid_num
curve = [[], ] * grid_num
data = [[], ] * grid_num

size = 300
x = [0, ]

for ids in range(grid_num):
    data[ids] = np.random.normal(size=1)
    layout_g[ids] = win.addPlot(row=ids % grid_row, col=ids // grid_row, )
    curve[ids] = layout_g[ids].plot(x=x, y=data[ids])


count = 0
start_t = time.time()


def update():
    global data, x, count, size
    count += 1
    # make graph sliding after a certain amount data are collected
    if count >= size:
        x = [*range(-1 * size + 1, 1)]
        for ids2 in range(grid_num):
            data[ids2][:-1] = data[ids2][1:]  # shift data in the array one sample left
            data[ids2][-1] = np.random.normal(size=1)
            curve[ids2].setData(x=x, y=data[ids2])
    else:
        x = [*range(-1 * count, 1)]
        for idx3 in range(grid_num):
            data[idx3] = np.append(data[idx3], np.random.normal(size=1))
            curve[idx3].setData(x=x, y=data[idx3])
    print(f'FPS:{round(count / (time.time() - start_t + 0.0000001), 2)}')


timer = pg.QtCore.QTimer()
timer.timeout.connect(update)
timer.start(10)

if __name__ == '__main__':
    import sys

    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtWidgets.QApplication.instance().exec_()
0 Answers
Related