Package: pglive
Live pyqtgraph plotPglive package adds support for thread-safe live plotting based on pyqtgraph.It supports PyQt5, PyQt6 and PySide6.DescriptionPyqtgraph doesn't offer easy way to implement live plotting out of the box.
The aim of PgLive module is to provide easy way of thread-safe live plotting.
To do this, PgLive provides DataConnector object, which consumes data
and manages data plotting. DataConnector interface provides Pause and Resume method, update rate and maximum number of
plotted points. All that needs to be done is to connect plots and data sources with DataConnector.
Once data is collected, DataConnector is sending signals to the GUI main loop.Focus on data handling - leave plotting to pglive.You can find many examples for PyQt5, PyQt6 or PySide6.Code exampleimportsysfrommathimportsinfromthreadingimportThreadfromtimeimportsleepfromPyQt6.QtWidgetsimportQApplicationfrompglive.sources.data_connectorimportDataConnectorfrompglive.sources.live_plotimportLiveLinePlotfrompglive.sources.live_plot_widgetimportLivePlotWidget"""Line plot is displayed in this example."""app=QApplication(sys.argv)running=Trueplot_widget=LivePlotWidget(title="Line Plot @ 100Hz")plot_curve=LiveLinePlot()plot_widget.addItem(plot_curve)# DataConnector holding 600 points and plots @ 100Hzdata_connector=DataConnector(plot_curve,max_points=600,update_rate=100)defsin_wave_generator(connector):"""Sine wave generator"""x=0whilerunning:x+=1data_point=sin(x*0.01)# Callback to plot new data pointconnector.cb_append_data_point(data_point,x)sleep(0.01)plot_widget.show()# Start sin_wave_generator in new Thread and send data to data_connectorThread(target=sin_wave_generator,args=(data_connector,)).start()app.exec()running=FalseOutput:To run built-in examples, use python3 -m parameter like:python3 -m pglive.examples_pyqt6.all_plot_typespython3 -m pglive.examples_pyqt6.crosshairUsing PyQt5/6 designerAdd QWidget to Your layoutPromote QWidget toLivePlotWidgetand set header file topglive.sources.live_plot_widgetClickAddandPromotebuttonAvailable plot typesPglive supports four plot types:LiveLinePlot,LiveScatterPlot,LiveHBarPlot(horizontal bar plot),LiveVBarPlot(vertical bar plot) andLiveCandleStickPlot.Plot speed optimizationsScaling plot view to plotted data has a huge impact on plotting performance.
Re-plotting might be laggy when using high update frequencies and multiple plots.To increase plotting performance, pglive introducesLiveAxisRange, that can be used inLivePlotWidget.
User can specify when and how is a new view of plotted data calculated.Have a look in thelive_plot_range.pyexample.In case you want to plot wider area with LiveAxisRange you can usecrop_offset_to_dataflag.
For example, you want to store 60 seconds, display 30 seconds in a view and move view every 1 second.
You will end up with big empty space to the left ifcrop_offset_to_data = False.
Take a look intocrop_offset_to_data.pyexample.Introduced inv0.4.0CrosshairPglive comes with built-in Crosshair as well. Take a look atcrosshair.pyexample.Leading linesLeading line displays horizontal or vertical line (or both) at the last plotted point.You can choose its color and which axis value is displayed along with it.Example atleading_line.pyAxisTo make life easier, pglive includes a few axis improvements:Colored axis line using newaxisPenattributeTime and DateTime tick format, converting timestamp into human-readable formatUsetick_angleattribute to change tick angle from 0 default degreeExample ataxis.pySummaryWith Pglive You've got an easy Thread-safe live plot implementation in Pyqt5, Pyqt6 or PySide6You can use allkwargsthat works inpyqtgraphUse your plots withDataConnectordirectlyIt works with Python3.9, 3.10, 3.11 and 3.12 as wellMultiple optimized plot typesMany examples for easy startIf you find PgLive helpful, please considersupporting me, it helps a lot!Thanks to all contributors, feel free to suggest missing feature or any bug onGitHub.