What is the easiest way to achieve realtime plotting in pyqtgraph

Pyqtgraph only enables realtime plotting by being quick to draw new plot data. How to achieve realtime plotting is highly dependent on the details and control flow in your application.

The most common ways are:

  1. Plot data within a loop that makes calls to QApplication.processEvents().

    pw = pg.plot()
    while True:
        ...
        pw.plot(x, y, clear=True)
        pg.QtGui.QApplication.processEvents()
    
  2. Use a QTimer to make repeated calls to a function that updates the plot.

    pw = pg.plot()
    timer = pg.QtCore.QTimer()
    def update():
        pw.plot(x, y, clear=True)
    timer.timeout.connect(update)
    timer.start(16)
    

Leave a Comment