pglive


Namepglive JSON
Version 0.7.4 PyPI version JSON
download
home_pagehttps://github.com/domarm-comat/pglive
SummaryLive plot for PyqtGraph
upload_time2024-02-05 20:19:39
maintainer
docs_urlNone
authorMartin Domaracky
requires_python>=3.9,<3.13
licenseMIT
keywords pyqtgraph realtime live plotting pyqt5 pyqt6 pyside6
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Live pyqtgraph plot

Pglive package adds support for thread-safe live plotting based on pyqtgraph.  
It supports PyQt5, PyQt6 and PySide6.

# Description #

Pyqtgraph 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 example #

```python
import sys
from math import sin
from threading import Thread
from time import sleep

from PyQt6.QtWidgets import QApplication

from pglive.sources.data_connector import DataConnector
from pglive.sources.live_plot import LiveLinePlot
from pglive.sources.live_plot_widget import LivePlotWidget

"""
Line plot is displayed in this example.
"""
app = QApplication(sys.argv)
running = True

plot_widget = LivePlotWidget(title="Line Plot @ 100Hz")
plot_curve = LiveLinePlot()
plot_widget.addItem(plot_curve)
# DataConnector holding 600 points and plots @ 100Hz
data_connector = DataConnector(plot_curve, max_points=600, update_rate=100)


def sin_wave_generator(connector):
    """Sine wave generator"""
    x = 0
    while running:
        x += 1
        data_point = sin(x * 0.01)
        # Callback to plot new data point
        connector.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_connector
Thread(target=sin_wave_generator, args=(data_connector,)).start()
app.exec()
running = False
```

Output:

![Plot example](https://i.postimg.cc/RFYGfNS6/pglive.gif)

To run built-in examples, use python3 -m parameter like:  
`python3 -m pglive.examples_pyqt6.all_plot_types`  
`python3 -m pglive.examples_pyqt6.crosshair`

# Using PyQt5/6 designer #

1. Add QWidget to Your layout
2. Promote QWidget to `LivePlotWidget` and set header file to `pglive.sources.live_plot_widget`
3. Click `Add` and `Promote` button

![All plot types](https://i.postimg.cc/m25NVJZm/designer-promotion.png)

# Available plot types #

Pglive supports four plot types: `LiveLinePlot`, `LiveScatterPlot`, `LiveHBarPlot` (horizontal bar plot),
`LiveVBarPlot` (vertical bar plot) and `LiveCandleStickPlot`.

![All plot types](https://i.postimg.cc/637CsKRC/pglive-allplots.gif)
![CandleStick plot](https://i.postimg.cc/0QcmMMb0/plot-candlestick.gif)
![live-categorized-bar.gif](https://i.postimg.cc/xqrwXXjY/live-categorized-bar.gif)

# Plot speed optimizations  #

Scaling 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 introduces `LiveAxisRange`, that can be used in `LivePlotWidget`.
User can specify when and how is a new view of plotted data calculated.

Have a look in the [live_plot_range.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/live_plot_range.py) example.

![Range_optimization](https://i.postimg.cc/3wrMbbTY/a.gif)

In case you want to plot wider area with LiveAxisRange you can use `crop_offset_to_data` flag.
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 if `crop_offset_to_data = False`.
Take a look into [crop_offset_to_data.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/crop_offset_to_data.py) example.

![crop_offset_to_data](https://i.postimg.cc/90X40Ng7/Peek-2022-09-24-15-20.gif)

Introduced in *v0.4.0*

# Crosshair #

Pglive comes with built-in Crosshair as well. Take a look at [crosshair.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/crosshair.py) example.

![Crosshair](https://i.postimg.cc/1z75GZLV/pglive-crosshair.gif)

# Leading lines #

Leading 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 at [leading_line.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/leading_line.py)

![Leading lines](https://i.postimg.cc/bYKQGBNp/leading-line.gif)

# Axis #

To make life easier, pglive includes a few axis improvements:

- Colored axis line using new `axisPen` attribute
- Time and DateTime tick format, converting timestamp into human-readable format
- Use `tick_angle` attribute to change tick angle from 0 default degree  

Example at [axis.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/axis.py)

[![Axis example](https://i.postimg.cc/SQ2hDxBr/Peek-2023-09-03-15-58.gif)](https://postimg.cc/RqBy04V6)

# Summary #

- With Pglive You've got an easy Thread-safe live plot implementation in Pyqt5, Pyqt6 or PySide6
- You can use all `kwargs` that works in [pyqtgraph](https://pyqtgraph.readthedocs.io/en/latest/getting_started/index.html#getting-started-ref)
- Use your plots with `DataConnector` directly
- It works with Python3.9, 3.10, 3.11 and 3.12 as well
- Multiple optimized plot types
- Many examples for easy start

If you find PgLive helpful, please consider [supporting me](https://ko-fi.com/domarmcomatsk), it helps a lot!  
Thanks to all contributors, feel free to suggest missing feature or any bug on [GitHub](https://github.com/domarm-comat/pglive/issues).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/domarm-comat/pglive",
    "name": "pglive",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<3.13",
    "maintainer_email": "",
    "keywords": "pyqtgraph,realtime,live,plotting,pyqt5,pyqt6,pyside6",
    "author": "Martin Domaracky",
    "author_email": "domarm@comat.sk",
    "download_url": "https://files.pythonhosted.org/packages/b7/e6/2ff7fc525217e73b31c2c653ea2980c379d30406af63753f861b4a5cb829/pglive-0.7.4.tar.gz",
    "platform": null,
    "description": "# Live pyqtgraph plot\n\nPglive package adds support for thread-safe live plotting based on pyqtgraph.  \nIt supports PyQt5, PyQt6 and PySide6.\n\n# Description #\n\nPyqtgraph doesn't offer easy way to implement live plotting out of the box.\nThe aim of PgLive module is to provide easy way of thread-safe live plotting.\nTo do this, PgLive provides DataConnector object, which consumes data \nand manages data plotting. DataConnector interface provides Pause and Resume method, update rate and maximum number of\nplotted points. All that needs to be done is to connect plots and data sources with DataConnector.\nOnce data is collected, DataConnector is sending signals to the GUI main loop.\n\n**Focus on data handling - leave plotting to pglive.**\n\nYou can find many examples for PyQt5, PyQt6 or PySide6.\n\n# Code example #\n\n```python\nimport sys\nfrom math import sin\nfrom threading import Thread\nfrom time import sleep\n\nfrom PyQt6.QtWidgets import QApplication\n\nfrom pglive.sources.data_connector import DataConnector\nfrom pglive.sources.live_plot import LiveLinePlot\nfrom pglive.sources.live_plot_widget import LivePlotWidget\n\n\"\"\"\nLine plot is displayed in this example.\n\"\"\"\napp = QApplication(sys.argv)\nrunning = True\n\nplot_widget = LivePlotWidget(title=\"Line Plot @ 100Hz\")\nplot_curve = LiveLinePlot()\nplot_widget.addItem(plot_curve)\n# DataConnector holding 600 points and plots @ 100Hz\ndata_connector = DataConnector(plot_curve, max_points=600, update_rate=100)\n\n\ndef sin_wave_generator(connector):\n    \"\"\"Sine wave generator\"\"\"\n    x = 0\n    while running:\n        x += 1\n        data_point = sin(x * 0.01)\n        # Callback to plot new data point\n        connector.cb_append_data_point(data_point, x)\n        sleep(0.01)\n\n\nplot_widget.show()\n# Start sin_wave_generator in new Thread and send data to data_connector\nThread(target=sin_wave_generator, args=(data_connector,)).start()\napp.exec()\nrunning = False\n```\n\nOutput:\n\n![Plot example](https://i.postimg.cc/RFYGfNS6/pglive.gif)\n\nTo run built-in examples, use python3 -m parameter like:  \n`python3 -m pglive.examples_pyqt6.all_plot_types`  \n`python3 -m pglive.examples_pyqt6.crosshair`\n\n# Using PyQt5/6 designer #\n\n1. Add QWidget to Your layout\n2. Promote QWidget to `LivePlotWidget` and set header file to `pglive.sources.live_plot_widget`\n3. Click `Add` and `Promote` button\n\n![All plot types](https://i.postimg.cc/m25NVJZm/designer-promotion.png)\n\n# Available plot types #\n\nPglive supports four plot types: `LiveLinePlot`, `LiveScatterPlot`, `LiveHBarPlot` (horizontal bar plot),\n`LiveVBarPlot` (vertical bar plot) and `LiveCandleStickPlot`.\n\n![All plot types](https://i.postimg.cc/637CsKRC/pglive-allplots.gif)\n![CandleStick plot](https://i.postimg.cc/0QcmMMb0/plot-candlestick.gif)\n![live-categorized-bar.gif](https://i.postimg.cc/xqrwXXjY/live-categorized-bar.gif)\n\n# Plot speed optimizations  #\n\nScaling plot view to plotted data has a huge impact on plotting performance.\nRe-plotting might be laggy when using high update frequencies and multiple plots.    \nTo increase plotting performance, pglive introduces `LiveAxisRange`, that can be used in `LivePlotWidget`.\nUser can specify when and how is a new view of plotted data calculated.\n\nHave a look in the [live_plot_range.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/live_plot_range.py) example.\n\n![Range_optimization](https://i.postimg.cc/3wrMbbTY/a.gif)\n\nIn case you want to plot wider area with LiveAxisRange you can use `crop_offset_to_data` flag.\nFor example, you want to store 60 seconds, display 30 seconds in a view and move view every 1 second.\nYou will end up with big empty space to the left if `crop_offset_to_data = False`.\nTake a look into [crop_offset_to_data.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/crop_offset_to_data.py) example.\n\n![crop_offset_to_data](https://i.postimg.cc/90X40Ng7/Peek-2022-09-24-15-20.gif)\n\nIntroduced in *v0.4.0*\n\n# Crosshair #\n\nPglive comes with built-in Crosshair as well. Take a look at [crosshair.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/crosshair.py) example.\n\n![Crosshair](https://i.postimg.cc/1z75GZLV/pglive-crosshair.gif)\n\n# Leading lines #\n\nLeading line displays horizontal or vertical line (or both) at the last plotted point.  \nYou can choose its color and which axis value is displayed along with it.  \nExample at [leading_line.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/leading_line.py)\n\n![Leading lines](https://i.postimg.cc/bYKQGBNp/leading-line.gif)\n\n# Axis #\n\nTo make life easier, pglive includes a few axis improvements:\n\n- Colored axis line using new `axisPen` attribute\n- Time and DateTime tick format, converting timestamp into human-readable format\n- Use `tick_angle` attribute to change tick angle from 0 default degree  \n\nExample at [axis.py](https://github.com/domarm-comat/pglive/blob/main/pglive/examples_pyqt6/axis.py)\n\n[![Axis example](https://i.postimg.cc/SQ2hDxBr/Peek-2023-09-03-15-58.gif)](https://postimg.cc/RqBy04V6)\n\n# Summary #\n\n- With Pglive You've got an easy Thread-safe live plot implementation in Pyqt5, Pyqt6 or PySide6\n- You can use all `kwargs` that works in [pyqtgraph](https://pyqtgraph.readthedocs.io/en/latest/getting_started/index.html#getting-started-ref)\n- Use your plots with `DataConnector` directly\n- It works with Python3.9, 3.10, 3.11 and 3.12 as well\n- Multiple optimized plot types\n- Many examples for easy start\n\nIf you find PgLive helpful, please consider [supporting me](https://ko-fi.com/domarmcomatsk), it helps a lot!  \nThanks to all contributors, feel free to suggest missing feature or any bug on [GitHub](https://github.com/domarm-comat/pglive/issues).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Live plot for PyqtGraph",
    "version": "0.7.4",
    "project_urls": {
        "Homepage": "https://github.com/domarm-comat/pglive",
        "Repository": "https://github.com/domarm-comat/pglive"
    },
    "split_keywords": [
        "pyqtgraph",
        "realtime",
        "live",
        "plotting",
        "pyqt5",
        "pyqt6",
        "pyside6"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b3dc3c39b584fcfc3547f03eb1f9af097694be297c89d95e18c0fc52c638a9a",
                "md5": "ad4261d7e11ac82e2217db89eddf1d10",
                "sha256": "be14cf4d8087488860a2e77b977f0f82e3e575eb4801e577830e38232a5d32f3"
            },
            "downloads": -1,
            "filename": "pglive-0.7.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ad4261d7e11ac82e2217db89eddf1d10",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<3.13",
            "size": 71775,
            "upload_time": "2024-02-05T20:19:38",
            "upload_time_iso_8601": "2024-02-05T20:19:38.066410Z",
            "url": "https://files.pythonhosted.org/packages/5b/3d/c3c39b584fcfc3547f03eb1f9af097694be297c89d95e18c0fc52c638a9a/pglive-0.7.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7e62ff7fc525217e73b31c2c653ea2980c379d30406af63753f861b4a5cb829",
                "md5": "a3a05c6090c67ed1629fc5071dce116c",
                "sha256": "2796dcf310110aa05780e8dd786d43df5b46b99934c44c438a7d92806c6bed5e"
            },
            "downloads": -1,
            "filename": "pglive-0.7.4.tar.gz",
            "has_sig": false,
            "md5_digest": "a3a05c6090c67ed1629fc5071dce116c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<3.13",
            "size": 39298,
            "upload_time": "2024-02-05T20:19:39",
            "upload_time_iso_8601": "2024-02-05T20:19:39.767338Z",
            "url": "https://files.pythonhosted.org/packages/b7/e6/2ff7fc525217e73b31c2c653ea2980c379d30406af63753f861b4a5cb829/pglive-0.7.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-05 20:19:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "domarm-comat",
    "github_project": "pglive",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pglive"
}
        
Elapsed time: 0.17398s