Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest way to achieve realtime plotting in pyqtgraph

I do not get how to achieve realtime plotting in pyqtgraph. The realisation of that is not implemented in the documentation yet.

Could anyone please provide an easy example ?

like image 222
dan_0 Avatar asked Aug 06 '13 12:08

dan_0


People also ask

Is Pyqtgraph faster than Matplotlib?

matplotlib: For plotting, pyqtgraph is not nearly as complete/mature as matplotlib, but runs much faster. Matplotlib is more aimed toward making publication-quality graphics, whereas pyqtgraph is intended for use in data acquisition and analysis applications.

What is PlotWidget?

The plot widget is used to graphically display data. The plotting panel can be added to the dashboard by opening up the "file" option on the top left of the dashboard, then selecting "Add Widget" (Figure 1) and clicking on "Plot Panel" (Figure 2).


1 Answers

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)
    
like image 145
Luke Avatar answered Oct 21 '22 02:10

Luke