dvg-pyqtgraph-threadsafe


Namedvg-pyqtgraph-threadsafe JSON
Version 3.4.0 PyPI version JSON
download
home_pagehttps://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe
SummaryPyQtGraph library providing thread-safe plot curves with underlying (ring) buffers.
upload_time2024-06-24 16:31:51
maintainerNone
docs_urlNone
authorDennis van Gils
requires_python>=3.6
licenseMIT
keywords ring buffer circular buffer pyqtgraph thread safe chart plot
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://img.shields.io/pypi/v/dvg-pyqtgraph-threadsafe
    :target: https://pypi.org/project/dvg-pyqtgraph-threadsafe
.. image:: https://img.shields.io/pypi/pyversions/dvg-pyqtgraph-threadsafe
    :target: https://pypi.org/project/dvg-pyqtgraph-threadsafe
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black
.. image:: https://img.shields.io/badge/License-MIT-purple.svg
    :target: https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/blob/master/LICENSE.txt


DvG_PyQtGraph_ThreadSafe
========================


*PyQtGraph library providing thread-safe plot curves with underlying (ring)
buffers.*

Supports PyQt5, PyQt6, PySide2 and PySide6.

- Github: https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe
- PyPI: https://pypi.org/project/dvg-pyqtgraph-threadsafe

Installation::

    pip install dvg-pyqtgraph-threadsafe

You must also ensure a Qt library is installed in your Python environment as
this library will not install one for you. Pick one (personal recommendation
PySide6)::

    pip install pyqt5
    pip install pyqt6
    pip install pyside2
    pip install pyside6

Futhermore, you might want to enable OpenGL hardware accelerated plotting by
installing PyOpenGL::

    pip install pyopengl

Useful links
------------

* Demos can be found in the `demos folder <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/tree/master/demos>`__.
* Benchmark tests and results can be found in the `benchmark folder <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/tree/master/benchmark>`__.
* Important notes on the specific use-case where another thread is actively requesting data at a high rate from an external device (e.g. an Arduino) to be pushed into a ThreadSafeCurve can be found `here <https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo/blob/master/README.rst#pyqtgraph--opengl-performance>`__.

.. image:: https://raw.githubusercontent.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/master/demos/demo_pyqtgraph_threadsafe.png

Overview
========


Classes ``HistoryChartCurve``, ``BufferedPlotCurve`` & ``PlotCurve`` wrap around
a ``pyqtgraph.PlotDataItem`` instance, called a *curve* for convenience. Data
can be safely appended or set from out of any thread.

The (x, y)-curve data is buffered internally to the class, relying on either a
circular/ring buffer or a regular array buffer:

* ``HistoryChartCurve``
    Ring buffer. The plotted x-data will be shifted such that the
    right-side is always set to 0. I.e., when `x` denotes time, the data is
    plotted backwards in time, hence the name *history* chart. The most
    recent data is on the right-side of the ring buffer.

* ``BufferedPlotCurve``
    Ring buffer. Data will be plotted as is. Can also act as a Lissajous
    figure.

* ``PlotCurve``
    Regular array buffer. Data will be plotted as is.

Usage
-----

    .. code-block:: python

        import sys

        from qtpy import QtWidgets
        import pyqtgraph as pg

        from dvg_pyqtgraph_threadsafe import HistoryChartCurve

        class MainWindow(QtWidgets.QWidget):
            def __init__(self, parent=None, **kwargs):
                super().__init__(parent, **kwargs)

                self.gw = pg.GraphicsLayoutWidget()
                self.plot_1 = self.gw.addPlot()

                # Create a HistoryChartCurve and have it wrap around a new
                # PlotDataItem as set by argument `linked_curve`.
                self.tscurve_1 = HistoryChartCurve(
                    capacity=5,
                    linked_curve=self.plot_1.plot(pen=pg.mkPen('r')),
                )

                grid = QtWidgets.QGridLayout(self)
                grid.addWidget(self.gw)

        app = QtWidgets.QApplication(sys.argv)
        window = MainWindow()

        # The following line could have been executed from inside of another thread:
        window.tscurve_1.extendData([1, 2, 3, 4, 5], [10, 20, 30, 20, 10])

        # Draw the curve from out of the main thread
        window.tscurve_1.update()

        window.show()
        sys.exit(app.exec())


Benchmark
=========

If you intend to use this library to plot 100.000s of points at a high frame
rate on your integrated GPU instead of on a dedicated (performance) GPU,
you might run into performance issues. Even when OpenGL hardware
acceleration is enabled.

I recommend you run the performance benchmark found in the
`benchmark folder <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/tree/master/benchmark>`_.
It can test for different PyQtGraph versions and Qt libraries on your
GPU of choice. I have found that the older ``pyqtgraph 0.11`` library sometimes
results in a better performance than ``pyqtgraph 0.12`` on integrated GPUs.
See `benchmark results <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/blob/master/benchmark/benchmark_results.rst>`_.


API
===

Class ThreadSafeCurve
---------------------

.. code-block:: python

    ThreadSafeCurve(
        capacity: int | None,
        linked_curve: pyqtgraph.PlotDataItem,
        shift_right_x_to_zero: bool = False,
        use_ringbuffer=None,
    )

.. Note::

    Provides the base class for a thread-safe plot *curve* to which
    (x, y)-data can be safely appended or set from out of any thread. It
    will wrap around the passed argument ``linked_curve`` of type
    ``pyqtgraph.PlotDataItem`` and will manage the (x, y)-data buffers
    underlying the curve.

    Intended multi-threaded operation: One or more threads push new data
    into the ``ThreadSafeCurve``-buffers. Another thread performs the GUI
    refresh by calling ``update()`` which will redraw the curve according
    to the current buffer contents.

    Args:
        capacity (``int``, optional):
            When an integer is supplied it defines the maximum number op points
            each of the x-data and y-data buffers can store. The x-data buffer
            and the y-data buffer are each a ring buffer. New readings are
            placed at the end (right-side) of the buffer, pushing out the oldest
            readings when the buffer has reached its maximum capacity (FIFO).
            Use methods ``appendData()`` and ``extendData()`` to push in new
            data.

            When ``None`` is supplied the x-data and y-data buffers are each a
            regular array buffer of undefined length. Use method ``setData()``
            to set the data.

        linked_curve (``pyqtgraph.PlotDataItem``):
            Instance of ``pyqtgraph.PlotDataItem`` to plot the buffered
            data out into.

        shift_right_x_to_zero (``bool``, optional):
            When plotting, should the x-data be shifted such that the
            right-side is always set to 0? Useful for history charts.

            Default: False

        use_ringbuffer (``bool``, deprecated):
            Deprecated since v3.1.0. Defined for backwards compatibility.
            Simply supply a value for ``capacity`` to enable use of a ring
            buffer.

    Attributes:
        x_axis_divisor (``float``):
            The x-data in the buffer will be divided by this factor when the
            plot curve is drawn. Useful to, e.g., transform the x-axis units
            from milliseconds to seconds or minutes.

            Default: 1

        y_axis_divisor (``float``):
            Same functionality as ``x_axis_divisor``.

            Default: 1

    Methods:
        * ``appendData(x, y)``
            Append a single (x, y)-data point to the ring buffer.

        * ``extendData(x_list, y_list)``
            Extend the ring buffer with a list of (x, y)-data points.

        * ``setData(x_list, y_list)``
            Set the (x, y)-data of the regular array buffer.

        * ``update(create_snapshot: bool = True)``
            Update the data behind the curve by creating a snapshot of the
            current contents of the buffer, and redraw the curve on screen.

            You can suppress updating the data behind the curve by setting parameter
            ``create_snapshot`` to False. The curve will then only be redrawn
            based on the old data. This is useful when the plot is paused.

        * ``clear()``
            Clear the contents of the curve and redraw.

        * ``name()``
            Get the name of the curve.

        * ``isVisible() -> bool``
            Is the curve visible?

        * ``setVisible(state: bool = True)``
            Set the visibility of the curve.

        * ``setDownsampling(*args, **kwargs)``
            All arguments will be passed onto method
            ``pyqtgraph.PlotDataItem.setDownsampling()`` of the underlying curve.


    Properties:
        * ``size -> Tuple[int, int]``:
            Number of elements currently contained in the underlying (x, y)-
            buffers of the curve. Note that this is not necessarily the number of
            elements of the currently drawn curve. Instead, it reflects the current
            sizes of the data buffers behind it that will be drawn onto screen by
            the next call to ``update()``.

Class HistoryChartCurve
-----------------------

.. code-block:: python

    HistoryChartCurve(
        capacity: int,
        linked_curve: pyqtgraph.PlotDataItem,
    )

.. Note::

    Inherits from: ``ThreadSafeCurve``

    Provides a thread-safe curve with underlying ring buffers for the
    (x, y)-data. New readings are placed at the end (right-side) of the
    buffer, pushing out the oldest readings when the buffer has reached its
    maximum capacity (FIFO). Use methods ``appendData()`` and
    ``extendData()`` to push in new data.

    The plotted x-data will be shifted such that the right-side is always
    set to 0. I.e., when ``x`` denotes time, the data is plotted backwards
    in time, hence the name *history* chart.

    See class ``ThreadSafeCurve`` for more details.

Class BufferedPlotCurve
-----------------------

.. code-block:: python

    BufferedPlotCurve(
        capacity: int,
        linked_curve: pyqtgraph.PlotDataItem,
    )

.. Note::

    Inherits from: ``ThreadSafeCurve``

    Provides a thread-safe curve with underlying ring buffers for the
    (x, y)-data. New readings are placed at the end (right-side) of the
    buffer, pushing out the oldest readings when the buffer has reached its
    maximum capacity (FIFO). Use methods ``appendData()`` and
    ``extendData()`` to push in new data.

    See class ``ThreadSafeCurve`` for more details.

Class PlotCurve
-----------------------

.. code-block:: python

    PlotCurve(
        capacity: int,
        linked_curve: pyqtgraph.PlotDataItem,
    )

.. Note::

    Inherits from: ``ThreadSafeCurve``

    Provides a thread-safe curve with underlying regular array buffers
    for the (x, y)-data. Use method ``setData()`` to set the data.

    See class ``ThreadSafeCurve`` for more details.

API Extras
==========

Class LegendSelect
------------------

.. code-block:: python

    LegendSelect(
        linked_curves: Sequence[pyqtgraph.PlotDataItem | ThreadSafeCurve],
        hide_toggle_button: bool = False,
        box_bg_color: QtGui.QColor = QtGui.QColor(0, 0, 0),
        box_width: int = 40,
        box_height: int = 23,
        parent=None,
    )

.. Note:: Inherits from: ``PyQt5.QtCore.QObject``

    Creates and manages a legend of all passed curves with checkboxes to
    show or hide each curve. The legend ends with a push button to show or
    hide all curves in one go. The full set of GUI elements is contained in
    attribute ``grid`` of type ``PyQt5.QtWidget.QGridLayout`` to be added to
    your GUI.

    Example grid::

        □ Curve 1  [  /  ]
        □ Curve 2  [  /  ]
        □ Curve 3  [  /  ]
        [ Show / Hide all]

    The initial visibility, name and pen of each curve will be retrieved
    from the members within the passed curves, i.e.:

        * ``curve.isVisible()``
        * ``curve.name()``
        * ``curve.opts["pen"]``

    Args:
        linked_curves (``Sequence[pyqtgraph.PlotDataItem | ThreadSafeCurve]``):
            Sequence of ``pyqtgraph.PlotDataItem`` or ``ThreadSafeCurve``
            instances to be controlled by the legend.

        hide_toggle_button (``bool``, optional):
            Default: False

        box_bg_color (``QtGui.QColor``, optional):
            Background color of the legend boxes.

            Default: ``QtGui.QColor(0, 0, 0)``

        box_width (``int``, optional):
            Default: 40

        box_height (``int``, optional):
            Default: 23

    Attributes:
        chkbs (``List[PyQt5.QtWidgets.QCheckbox]``):
            List of checkboxes to control the visiblity of each curve.

        painted_boxes (``List[PyQt5.QtWidgets.QWidget]``):
            List of painted boxes illustrating the pen of each curve.

        qpbt_toggle (``PyQt5.QtWidgets.QPushButton``):
            Push button instance that toggles showing/hiding all curves in
            one go.

        grid (``PyQt5.QtWidgets.QGridLayout``):
            The full set of GUI elements combined into a grid to be added
            to your GUI.

Class PlotManager
------------------

.. code-block:: python

    PlotManager(
        parent=None,
    )

.. Note:: Inherits from: ``PyQt5.QtCore.QObject``

    Creates and manages a collection of pushbuttons with predefined actions
    operating on the linked plots and curves. The full set of pushbuttons is
    contained in attribute ``grid`` of type ``PyQt5.QtWidget.QGridLayout`` to be
    added to your GUI.

    Example grid::

        [   Full range  ]
        [auto x] [auto y]
        [      0:30     ]
        [      1:00     ]
        [      3:00     ]
        [     10:00     ]

        [     Clear     ]

    The grid starts empty and is build up by calling the following methods:
        - ``add_autorange_buttons()``: Adds the [Full range], [auto x] and
          [auto y] buttons.

        - ``add_preset_buttons()``: Adds presets on the x-axis range to zoom to.

        - ``add_clear_button()``: Adds the 'Clear' button.

    Args:
        parent (``PyQt5.QtWidgets.QWidget``):
            Needs to be set to the parent ``QWidget`` for the ``QMessageBox`` as
            fired by button ``Clear`` to appear centered and modal to.

    Attributes:
        grid (``PyQt5.QtWidgets.QGridLayout``):
            The full set of pushbuttons combined into a grid to be added
            to your GUI.

Changelog
=========

3.4.0 (2024-06-24)
------------------
Code quality improvements:

* Using ``qtpy`` library instead of my own Qt5/6 mechanism
* Using f-strings
* Extended API and docstrings, like on `PlotManager`.
* Arguments `linked_curves` and `linked_plots` are hinted as `Sequence` instead
  of as `List`

Added support:

* Support for Numpy 2.0

3.3.0 (2023-02-27)
------------------
* Raise `ImportError` instead of general `Exception`

3.2.6 (2022-10-13)
------------------
* Added link to notes on use-case: DAQ

3.2.5 (2022-10-13)
------------------
* Minor edit: Using explicit arguments `x` and `y` to set the curve data and set
  the flag `skipFiniteCheck=True`. Both save (marginal) CPU time.

3.2.4 (2022-10-12)
------------------
* Bug fix: Snapshot creation checks if internal buffer is of type RingBuffer and
  casts to numpy.ndarray. This resolves an intermittent error where the
  `isfinite` boolean return array was operating as mask on the RingBuffer, which
  fails. The boolean return array now always operates on numpy.ndarray.
* Fix for external bug in `paintGL` of `pyqtgraph\graphicsItems\PlotCurveItem.py`:
  Added explicit check to ensure that the curve is only drawn when it has more
  than 1 point.
* Added benchmark running `python=3.10` and `pyqtgraph==0.13.1`

3.2.3 (2022-10-11)
------------------
* Fixed bug when using PyQt6: `QMessageBox.Yes` --> `QMessageBox.StandardButton.Yes`

3.2.2 (2022-09-18)
------------------
* Updated discussion on benchmarks
* The batch file for auto-creation of the conda environments found in the
  benchmark folder now uses the conda-forge channel.

3.2.1 (2022-09-17)
------------------
* Neater mechanism to support both PyQt and PySide
* Added benchmarks
* Improved demos

3.2.0 (2022-09-13)
------------------
* Added support for PyQt5, PyQt6, PySide2 and PySide6 as suggested via a pull
  request by Mathijs van Gorcum (https://github.com/mvgorcum).

3.1.0 (2021-05-10)
------------------
* Removed redundant argument ``capacity`` from init ``PlotCurve()``. It is
  not using a ringbuffer and, hence, does not need a capacity.

3.0.1 (2020-08-07)
------------------
Bug-fixes:

* The use of ``typing.TypedDict`` broke support under Python 3.6
  and 3.7. Fixed by conditional import ``typing_extensions``.
* Curve plotting was broken when ``setClipToView(True)`` and the curve
  data extended past the viewbox limits, when not using OpenGL. The cause was
  my incorrect calculation of ``connect``. Fixed by commenting out ``connect``
  again. Curves will now show continuously (linear interpolation) whenever a NaN
  is encountered, instead of as correctly fragmented. That's acceptable.

3.0.0 (2020-08-07)
------------------
* Renamed parameter ``LegendSelect.curves`` to
  ``LegendSelect.linked_curves``
* Changed base of class ``LegendSelect()`` from ``QWidget`` to ``QObject``
* Added class ``PlotManager()``

2.0.1 (2020-08-03)
------------------
* Workaround: ``PyQt5 >= 5.12.3`` causes a bug in ``PyQtGraph`` where a
  curve won't render if it contains NaNs (but only in the case when OpenGL is
  disabled). The curve will now be displayed correctly, i.e., fragmented
  whenever a NaN is encountered. When OpenGL is enabled, linear interpolation
  will occur at the gaps as per ``pyqtgraph.plotCurveItem.paintGL()``.

2.0.0 (2020-08-02)
------------------
* Method names are now conform the ``PyQtGraph`` naming style. I.e.
  ``setData()`` vs. ``set_data()``, etc.
* The default values of ``PyQtGraph`` are no longer being overwritten.
* Added class ``LegendSelect``

1.0.0 (2020-07-30)
------------------
* First release on PyPI

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe",
    "name": "dvg-pyqtgraph-threadsafe",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "ring buffer, circular buffer, pyqtgraph, thread safe, chart, plot",
    "author": "Dennis van Gils",
    "author_email": "vangils.dennis@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/59/0c/3589bcab501bf780903f918925dbc792b0649f92028e75d76ce28c46d713/dvg_pyqtgraph_threadsafe-3.4.0.tar.gz",
    "platform": null,
    "description": ".. image:: https://img.shields.io/pypi/v/dvg-pyqtgraph-threadsafe\r\n    :target: https://pypi.org/project/dvg-pyqtgraph-threadsafe\r\n.. image:: https://img.shields.io/pypi/pyversions/dvg-pyqtgraph-threadsafe\r\n    :target: https://pypi.org/project/dvg-pyqtgraph-threadsafe\r\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\r\n    :target: https://github.com/psf/black\r\n.. image:: https://img.shields.io/badge/License-MIT-purple.svg\r\n    :target: https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/blob/master/LICENSE.txt\r\n\r\n\r\nDvG_PyQtGraph_ThreadSafe\r\n========================\r\n\r\n\r\n*PyQtGraph library providing thread-safe plot curves with underlying (ring)\r\nbuffers.*\r\n\r\nSupports PyQt5, PyQt6, PySide2 and PySide6.\r\n\r\n- Github: https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe\r\n- PyPI: https://pypi.org/project/dvg-pyqtgraph-threadsafe\r\n\r\nInstallation::\r\n\r\n    pip install dvg-pyqtgraph-threadsafe\r\n\r\nYou must also ensure a Qt library is installed in your Python environment as\r\nthis library will not install one for you. Pick one (personal recommendation\r\nPySide6)::\r\n\r\n    pip install pyqt5\r\n    pip install pyqt6\r\n    pip install pyside2\r\n    pip install pyside6\r\n\r\nFuthermore, you might want to enable OpenGL hardware accelerated plotting by\r\ninstalling PyOpenGL::\r\n\r\n    pip install pyopengl\r\n\r\nUseful links\r\n------------\r\n\r\n* Demos can be found in the `demos folder <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/tree/master/demos>`__.\r\n* Benchmark tests and results can be found in the `benchmark folder <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/tree/master/benchmark>`__.\r\n* Important notes on the specific use-case where another thread is actively requesting data at a high rate from an external device (e.g. an Arduino) to be pushed into a ThreadSafeCurve can be found `here <https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo/blob/master/README.rst#pyqtgraph--opengl-performance>`__.\r\n\r\n.. image:: https://raw.githubusercontent.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/master/demos/demo_pyqtgraph_threadsafe.png\r\n\r\nOverview\r\n========\r\n\r\n\r\nClasses ``HistoryChartCurve``, ``BufferedPlotCurve`` & ``PlotCurve`` wrap around\r\na ``pyqtgraph.PlotDataItem`` instance, called a *curve* for convenience. Data\r\ncan be safely appended or set from out of any thread.\r\n\r\nThe (x, y)-curve data is buffered internally to the class, relying on either a\r\ncircular/ring buffer or a regular array buffer:\r\n\r\n* ``HistoryChartCurve``\r\n    Ring buffer. The plotted x-data will be shifted such that the\r\n    right-side is always set to 0. I.e., when `x` denotes time, the data is\r\n    plotted backwards in time, hence the name *history* chart. The most\r\n    recent data is on the right-side of the ring buffer.\r\n\r\n* ``BufferedPlotCurve``\r\n    Ring buffer. Data will be plotted as is. Can also act as a Lissajous\r\n    figure.\r\n\r\n* ``PlotCurve``\r\n    Regular array buffer. Data will be plotted as is.\r\n\r\nUsage\r\n-----\r\n\r\n    .. code-block:: python\r\n\r\n        import sys\r\n\r\n        from qtpy import QtWidgets\r\n        import pyqtgraph as pg\r\n\r\n        from dvg_pyqtgraph_threadsafe import HistoryChartCurve\r\n\r\n        class MainWindow(QtWidgets.QWidget):\r\n            def __init__(self, parent=None, **kwargs):\r\n                super().__init__(parent, **kwargs)\r\n\r\n                self.gw = pg.GraphicsLayoutWidget()\r\n                self.plot_1 = self.gw.addPlot()\r\n\r\n                # Create a HistoryChartCurve and have it wrap around a new\r\n                # PlotDataItem as set by argument `linked_curve`.\r\n                self.tscurve_1 = HistoryChartCurve(\r\n                    capacity=5,\r\n                    linked_curve=self.plot_1.plot(pen=pg.mkPen('r')),\r\n                )\r\n\r\n                grid = QtWidgets.QGridLayout(self)\r\n                grid.addWidget(self.gw)\r\n\r\n        app = QtWidgets.QApplication(sys.argv)\r\n        window = MainWindow()\r\n\r\n        # The following line could have been executed from inside of another thread:\r\n        window.tscurve_1.extendData([1, 2, 3, 4, 5], [10, 20, 30, 20, 10])\r\n\r\n        # Draw the curve from out of the main thread\r\n        window.tscurve_1.update()\r\n\r\n        window.show()\r\n        sys.exit(app.exec())\r\n\r\n\r\nBenchmark\r\n=========\r\n\r\nIf you intend to use this library to plot 100.000s of points at a high frame\r\nrate on your integrated GPU instead of on a dedicated (performance) GPU,\r\nyou might run into performance issues. Even when OpenGL hardware\r\nacceleration is enabled.\r\n\r\nI recommend you run the performance benchmark found in the\r\n`benchmark folder <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/tree/master/benchmark>`_.\r\nIt can test for different PyQtGraph versions and Qt libraries on your\r\nGPU of choice. I have found that the older ``pyqtgraph 0.11`` library sometimes\r\nresults in a better performance than ``pyqtgraph 0.12`` on integrated GPUs.\r\nSee `benchmark results <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/blob/master/benchmark/benchmark_results.rst>`_.\r\n\r\n\r\nAPI\r\n===\r\n\r\nClass ThreadSafeCurve\r\n---------------------\r\n\r\n.. code-block:: python\r\n\r\n    ThreadSafeCurve(\r\n        capacity: int | None,\r\n        linked_curve: pyqtgraph.PlotDataItem,\r\n        shift_right_x_to_zero: bool = False,\r\n        use_ringbuffer=None,\r\n    )\r\n\r\n.. Note::\r\n\r\n    Provides the base class for a thread-safe plot *curve* to which\r\n    (x, y)-data can be safely appended or set from out of any thread. It\r\n    will wrap around the passed argument ``linked_curve`` of type\r\n    ``pyqtgraph.PlotDataItem`` and will manage the (x, y)-data buffers\r\n    underlying the curve.\r\n\r\n    Intended multi-threaded operation: One or more threads push new data\r\n    into the ``ThreadSafeCurve``-buffers. Another thread performs the GUI\r\n    refresh by calling ``update()`` which will redraw the curve according\r\n    to the current buffer contents.\r\n\r\n    Args:\r\n        capacity (``int``, optional):\r\n            When an integer is supplied it defines the maximum number op points\r\n            each of the x-data and y-data buffers can store. The x-data buffer\r\n            and the y-data buffer are each a ring buffer. New readings are\r\n            placed at the end (right-side) of the buffer, pushing out the oldest\r\n            readings when the buffer has reached its maximum capacity (FIFO).\r\n            Use methods ``appendData()`` and ``extendData()`` to push in new\r\n            data.\r\n\r\n            When ``None`` is supplied the x-data and y-data buffers are each a\r\n            regular array buffer of undefined length. Use method ``setData()``\r\n            to set the data.\r\n\r\n        linked_curve (``pyqtgraph.PlotDataItem``):\r\n            Instance of ``pyqtgraph.PlotDataItem`` to plot the buffered\r\n            data out into.\r\n\r\n        shift_right_x_to_zero (``bool``, optional):\r\n            When plotting, should the x-data be shifted such that the\r\n            right-side is always set to 0? Useful for history charts.\r\n\r\n            Default: False\r\n\r\n        use_ringbuffer (``bool``, deprecated):\r\n            Deprecated since v3.1.0. Defined for backwards compatibility.\r\n            Simply supply a value for ``capacity`` to enable use of a ring\r\n            buffer.\r\n\r\n    Attributes:\r\n        x_axis_divisor (``float``):\r\n            The x-data in the buffer will be divided by this factor when the\r\n            plot curve is drawn. Useful to, e.g., transform the x-axis units\r\n            from milliseconds to seconds or minutes.\r\n\r\n            Default: 1\r\n\r\n        y_axis_divisor (``float``):\r\n            Same functionality as ``x_axis_divisor``.\r\n\r\n            Default: 1\r\n\r\n    Methods:\r\n        * ``appendData(x, y)``\r\n            Append a single (x, y)-data point to the ring buffer.\r\n\r\n        * ``extendData(x_list, y_list)``\r\n            Extend the ring buffer with a list of (x, y)-data points.\r\n\r\n        * ``setData(x_list, y_list)``\r\n            Set the (x, y)-data of the regular array buffer.\r\n\r\n        * ``update(create_snapshot: bool = True)``\r\n            Update the data behind the curve by creating a snapshot of the\r\n            current contents of the buffer, and redraw the curve on screen.\r\n\r\n            You can suppress updating the data behind the curve by setting parameter\r\n            ``create_snapshot`` to False. The curve will then only be redrawn\r\n            based on the old data. This is useful when the plot is paused.\r\n\r\n        * ``clear()``\r\n            Clear the contents of the curve and redraw.\r\n\r\n        * ``name()``\r\n            Get the name of the curve.\r\n\r\n        * ``isVisible() -> bool``\r\n            Is the curve visible?\r\n\r\n        * ``setVisible(state: bool = True)``\r\n            Set the visibility of the curve.\r\n\r\n        * ``setDownsampling(*args, **kwargs)``\r\n            All arguments will be passed onto method\r\n            ``pyqtgraph.PlotDataItem.setDownsampling()`` of the underlying curve.\r\n\r\n\r\n    Properties:\r\n        * ``size -> Tuple[int, int]``:\r\n            Number of elements currently contained in the underlying (x, y)-\r\n            buffers of the curve. Note that this is not necessarily the number of\r\n            elements of the currently drawn curve. Instead, it reflects the current\r\n            sizes of the data buffers behind it that will be drawn onto screen by\r\n            the next call to ``update()``.\r\n\r\nClass HistoryChartCurve\r\n-----------------------\r\n\r\n.. code-block:: python\r\n\r\n    HistoryChartCurve(\r\n        capacity: int,\r\n        linked_curve: pyqtgraph.PlotDataItem,\r\n    )\r\n\r\n.. Note::\r\n\r\n    Inherits from: ``ThreadSafeCurve``\r\n\r\n    Provides a thread-safe curve with underlying ring buffers for the\r\n    (x, y)-data. New readings are placed at the end (right-side) of the\r\n    buffer, pushing out the oldest readings when the buffer has reached its\r\n    maximum capacity (FIFO). Use methods ``appendData()`` and\r\n    ``extendData()`` to push in new data.\r\n\r\n    The plotted x-data will be shifted such that the right-side is always\r\n    set to 0. I.e., when ``x`` denotes time, the data is plotted backwards\r\n    in time, hence the name *history* chart.\r\n\r\n    See class ``ThreadSafeCurve`` for more details.\r\n\r\nClass BufferedPlotCurve\r\n-----------------------\r\n\r\n.. code-block:: python\r\n\r\n    BufferedPlotCurve(\r\n        capacity: int,\r\n        linked_curve: pyqtgraph.PlotDataItem,\r\n    )\r\n\r\n.. Note::\r\n\r\n    Inherits from: ``ThreadSafeCurve``\r\n\r\n    Provides a thread-safe curve with underlying ring buffers for the\r\n    (x, y)-data. New readings are placed at the end (right-side) of the\r\n    buffer, pushing out the oldest readings when the buffer has reached its\r\n    maximum capacity (FIFO). Use methods ``appendData()`` and\r\n    ``extendData()`` to push in new data.\r\n\r\n    See class ``ThreadSafeCurve`` for more details.\r\n\r\nClass PlotCurve\r\n-----------------------\r\n\r\n.. code-block:: python\r\n\r\n    PlotCurve(\r\n        capacity: int,\r\n        linked_curve: pyqtgraph.PlotDataItem,\r\n    )\r\n\r\n.. Note::\r\n\r\n    Inherits from: ``ThreadSafeCurve``\r\n\r\n    Provides a thread-safe curve with underlying regular array buffers\r\n    for the (x, y)-data. Use method ``setData()`` to set the data.\r\n\r\n    See class ``ThreadSafeCurve`` for more details.\r\n\r\nAPI Extras\r\n==========\r\n\r\nClass LegendSelect\r\n------------------\r\n\r\n.. code-block:: python\r\n\r\n    LegendSelect(\r\n        linked_curves: Sequence[pyqtgraph.PlotDataItem | ThreadSafeCurve],\r\n        hide_toggle_button: bool = False,\r\n        box_bg_color: QtGui.QColor = QtGui.QColor(0, 0, 0),\r\n        box_width: int = 40,\r\n        box_height: int = 23,\r\n        parent=None,\r\n    )\r\n\r\n.. Note:: Inherits from: ``PyQt5.QtCore.QObject``\r\n\r\n    Creates and manages a legend of all passed curves with checkboxes to\r\n    show or hide each curve. The legend ends with a push button to show or\r\n    hide all curves in one go. The full set of GUI elements is contained in\r\n    attribute ``grid`` of type ``PyQt5.QtWidget.QGridLayout`` to be added to\r\n    your GUI.\r\n\r\n    Example grid::\r\n\r\n        \u25a1 Curve 1  [  /  ]\r\n        \u25a1 Curve 2  [  /  ]\r\n        \u25a1 Curve 3  [  /  ]\r\n        [ Show / Hide all]\r\n\r\n    The initial visibility, name and pen of each curve will be retrieved\r\n    from the members within the passed curves, i.e.:\r\n\r\n        * ``curve.isVisible()``\r\n        * ``curve.name()``\r\n        * ``curve.opts[\"pen\"]``\r\n\r\n    Args:\r\n        linked_curves (``Sequence[pyqtgraph.PlotDataItem | ThreadSafeCurve]``):\r\n            Sequence of ``pyqtgraph.PlotDataItem`` or ``ThreadSafeCurve``\r\n            instances to be controlled by the legend.\r\n\r\n        hide_toggle_button (``bool``, optional):\r\n            Default: False\r\n\r\n        box_bg_color (``QtGui.QColor``, optional):\r\n            Background color of the legend boxes.\r\n\r\n            Default: ``QtGui.QColor(0, 0, 0)``\r\n\r\n        box_width (``int``, optional):\r\n            Default: 40\r\n\r\n        box_height (``int``, optional):\r\n            Default: 23\r\n\r\n    Attributes:\r\n        chkbs (``List[PyQt5.QtWidgets.QCheckbox]``):\r\n            List of checkboxes to control the visiblity of each curve.\r\n\r\n        painted_boxes (``List[PyQt5.QtWidgets.QWidget]``):\r\n            List of painted boxes illustrating the pen of each curve.\r\n\r\n        qpbt_toggle (``PyQt5.QtWidgets.QPushButton``):\r\n            Push button instance that toggles showing/hiding all curves in\r\n            one go.\r\n\r\n        grid (``PyQt5.QtWidgets.QGridLayout``):\r\n            The full set of GUI elements combined into a grid to be added\r\n            to your GUI.\r\n\r\nClass PlotManager\r\n------------------\r\n\r\n.. code-block:: python\r\n\r\n    PlotManager(\r\n        parent=None,\r\n    )\r\n\r\n.. Note:: Inherits from: ``PyQt5.QtCore.QObject``\r\n\r\n    Creates and manages a collection of pushbuttons with predefined actions\r\n    operating on the linked plots and curves. The full set of pushbuttons is\r\n    contained in attribute ``grid`` of type ``PyQt5.QtWidget.QGridLayout`` to be\r\n    added to your GUI.\r\n\r\n    Example grid::\r\n\r\n        [   Full range  ]\r\n        [auto x] [auto y]\r\n        [      0:30     ]\r\n        [      1:00     ]\r\n        [      3:00     ]\r\n        [     10:00     ]\r\n\r\n        [     Clear     ]\r\n\r\n    The grid starts empty and is build up by calling the following methods:\r\n        - ``add_autorange_buttons()``: Adds the [Full range], [auto x] and\r\n          [auto y] buttons.\r\n\r\n        - ``add_preset_buttons()``: Adds presets on the x-axis range to zoom to.\r\n\r\n        - ``add_clear_button()``: Adds the 'Clear' button.\r\n\r\n    Args:\r\n        parent (``PyQt5.QtWidgets.QWidget``):\r\n            Needs to be set to the parent ``QWidget`` for the ``QMessageBox`` as\r\n            fired by button ``Clear`` to appear centered and modal to.\r\n\r\n    Attributes:\r\n        grid (``PyQt5.QtWidgets.QGridLayout``):\r\n            The full set of pushbuttons combined into a grid to be added\r\n            to your GUI.\r\n\r\nChangelog\r\n=========\r\n\r\n3.4.0 (2024-06-24)\r\n------------------\r\nCode quality improvements:\r\n\r\n* Using ``qtpy`` library instead of my own Qt5/6 mechanism\r\n* Using f-strings\r\n* Extended API and docstrings, like on `PlotManager`.\r\n* Arguments `linked_curves` and `linked_plots` are hinted as `Sequence` instead\r\n  of as `List`\r\n\r\nAdded support:\r\n\r\n* Support for Numpy 2.0\r\n\r\n3.3.0 (2023-02-27)\r\n------------------\r\n* Raise `ImportError` instead of general `Exception`\r\n\r\n3.2.6 (2022-10-13)\r\n------------------\r\n* Added link to notes on use-case: DAQ\r\n\r\n3.2.5 (2022-10-13)\r\n------------------\r\n* Minor edit: Using explicit arguments `x` and `y` to set the curve data and set\r\n  the flag `skipFiniteCheck=True`. Both save (marginal) CPU time.\r\n\r\n3.2.4 (2022-10-12)\r\n------------------\r\n* Bug fix: Snapshot creation checks if internal buffer is of type RingBuffer and\r\n  casts to numpy.ndarray. This resolves an intermittent error where the\r\n  `isfinite` boolean return array was operating as mask on the RingBuffer, which\r\n  fails. The boolean return array now always operates on numpy.ndarray.\r\n* Fix for external bug in `paintGL` of `pyqtgraph\\graphicsItems\\PlotCurveItem.py`:\r\n  Added explicit check to ensure that the curve is only drawn when it has more\r\n  than 1 point.\r\n* Added benchmark running `python=3.10` and `pyqtgraph==0.13.1`\r\n\r\n3.2.3 (2022-10-11)\r\n------------------\r\n* Fixed bug when using PyQt6: `QMessageBox.Yes` --> `QMessageBox.StandardButton.Yes`\r\n\r\n3.2.2 (2022-09-18)\r\n------------------\r\n* Updated discussion on benchmarks\r\n* The batch file for auto-creation of the conda environments found in the\r\n  benchmark folder now uses the conda-forge channel.\r\n\r\n3.2.1 (2022-09-17)\r\n------------------\r\n* Neater mechanism to support both PyQt and PySide\r\n* Added benchmarks\r\n* Improved demos\r\n\r\n3.2.0 (2022-09-13)\r\n------------------\r\n* Added support for PyQt5, PyQt6, PySide2 and PySide6 as suggested via a pull\r\n  request by Mathijs van Gorcum (https://github.com/mvgorcum).\r\n\r\n3.1.0 (2021-05-10)\r\n------------------\r\n* Removed redundant argument ``capacity`` from init ``PlotCurve()``. It is\r\n  not using a ringbuffer and, hence, does not need a capacity.\r\n\r\n3.0.1 (2020-08-07)\r\n------------------\r\nBug-fixes:\r\n\r\n* The use of ``typing.TypedDict`` broke support under Python 3.6\r\n  and 3.7. Fixed by conditional import ``typing_extensions``.\r\n* Curve plotting was broken when ``setClipToView(True)`` and the curve\r\n  data extended past the viewbox limits, when not using OpenGL. The cause was\r\n  my incorrect calculation of ``connect``. Fixed by commenting out ``connect``\r\n  again. Curves will now show continuously (linear interpolation) whenever a NaN\r\n  is encountered, instead of as correctly fragmented. That's acceptable.\r\n\r\n3.0.0 (2020-08-07)\r\n------------------\r\n* Renamed parameter ``LegendSelect.curves`` to\r\n  ``LegendSelect.linked_curves``\r\n* Changed base of class ``LegendSelect()`` from ``QWidget`` to ``QObject``\r\n* Added class ``PlotManager()``\r\n\r\n2.0.1 (2020-08-03)\r\n------------------\r\n* Workaround: ``PyQt5 >= 5.12.3`` causes a bug in ``PyQtGraph`` where a\r\n  curve won't render if it contains NaNs (but only in the case when OpenGL is\r\n  disabled). The curve will now be displayed correctly, i.e., fragmented\r\n  whenever a NaN is encountered. When OpenGL is enabled, linear interpolation\r\n  will occur at the gaps as per ``pyqtgraph.plotCurveItem.paintGL()``.\r\n\r\n2.0.0 (2020-08-02)\r\n------------------\r\n* Method names are now conform the ``PyQtGraph`` naming style. I.e.\r\n  ``setData()`` vs. ``set_data()``, etc.\r\n* The default values of ``PyQtGraph`` are no longer being overwritten.\r\n* Added class ``LegendSelect``\r\n\r\n1.0.0 (2020-07-30)\r\n------------------\r\n* First release on PyPI\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PyQtGraph library providing thread-safe plot curves with underlying (ring) buffers.",
    "version": "3.4.0",
    "project_urls": {
        "Homepage": "https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe",
        "Issue Tracker": "https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-threadsafe/issues"
    },
    "split_keywords": [
        "ring buffer",
        " circular buffer",
        " pyqtgraph",
        " thread safe",
        " chart",
        " plot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "000daee2d2b7ba08d3ff934d8cf7b3865a9d1e536ee212a7d53e7a2271c25662",
                "md5": "4703890796da8453af125b3c8c421093",
                "sha256": "43e7d531b46a2abf68c7ca782fe679f3a7004ea0e6d25155b5af004f70f1a3b1"
            },
            "downloads": -1,
            "filename": "dvg_pyqtgraph_threadsafe-3.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4703890796da8453af125b3c8c421093",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 17420,
            "upload_time": "2024-06-24T16:31:50",
            "upload_time_iso_8601": "2024-06-24T16:31:50.248191Z",
            "url": "https://files.pythonhosted.org/packages/00/0d/aee2d2b7ba08d3ff934d8cf7b3865a9d1e536ee212a7d53e7a2271c25662/dvg_pyqtgraph_threadsafe-3.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "590c3589bcab501bf780903f918925dbc792b0649f92028e75d76ce28c46d713",
                "md5": "a65435eecd8e109c95c6c4396c8ba12d",
                "sha256": "1cbd7aceabe0b85c86921e9ed6e6a03a782aa5e7301c7faf896b486df52c30f7"
            },
            "downloads": -1,
            "filename": "dvg_pyqtgraph_threadsafe-3.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a65435eecd8e109c95c6c4396c8ba12d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 106847,
            "upload_time": "2024-06-24T16:31:51",
            "upload_time_iso_8601": "2024-06-24T16:31:51.838012Z",
            "url": "https://files.pythonhosted.org/packages/59/0c/3589bcab501bf780903f918925dbc792b0649f92028e75d76ce28c46d713/dvg_pyqtgraph_threadsafe-3.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-24 16:31:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Dennis-van-Gils",
    "github_project": "python-dvg-pyqtgraph-threadsafe",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dvg-pyqtgraph-threadsafe"
}
        
Elapsed time: 0.31094s