edifice.extra.pyqtgraph_plot.PyQtPlot#

class edifice.extra.pyqtgraph_plot.PyQtPlot(plot_fun, **kwargs)[source]#

Bases: QtWidgetElement[PlotWidget]

A PyQtGraph PlotWidget.

Requires PyQtGraph.

It’s important to import edifice before importing pyqtgraph, so that pyqtgraph detects the same PyQt6 or PySide6 package used by edifice.

Example:

import numpy as np
from edifice import View, component
from edifice.extra import PyQtPlot
import pyqtgraph as pg

@component
def Component(self):

    def plot_fun(plot_item: pg.PlotItem):
        xs = np.linspace(-10, 10, 100)
        ys = np.sin(xs)
        plot_item.plot(x=xs, y=ys)

    PyQtPlot(plot_fun=plot_fun)

If you want a non-interactive plot that doesn’t respond to the mouse, you can disable mouse interaction with the plot by setting properties on the PlotItem.

Example:

def plot_fun(plot_item: pg.PlotItem):
    plot_item.setMouseEnabled(x=False, y=False)
    plot_item.hideButtons()
    ...

A more complete way to disable mouse interaction is to set the PlotWidget to be transparent for mouse events.

Example:

def plot_fun(plot_item: pg.PlotItem):
    cast(
        pg.PlotWidget, plot_item.getViewWidget()
    ).setAttribute(PySide6.QtCore.Qt.WidgetAttribute.WA_TransparentForMouseEvents)
Parameters:

plot_fun (Callable[[PlotItem], None]) –

Function which takes a PyQtGraph PlotItem and calls plot().

Edifice will call clear() before calling plot_fun.

Methods

__init__(plot_fun, **kwargs)

register_ref(reference)

Registers provided Reference to this Element.

set_key(key)

Set the key of an Element.

Attributes

children

The children of this Element.

props

The props of this Element.

underlying

The underlying QWidget, which may not exist if this Element has not rendered.