magicclass.ext.pyqtgraph package

Subpackages

Submodules

magicclass.ext.pyqtgraph.components module

class magicclass.ext.pyqtgraph.components.GraphicComponent[source]

Bases: object

native: pyqtgraph.graphicsItems.GraphicsObject.GraphicsObject
update(**kwargs)[source]
property visible: bool

Linear region visibility.

class magicclass.ext.pyqtgraph.components.Legend(offset=(0, 0))[source]

Bases: magicclass.ext.pyqtgraph.components.GraphicComponent

property background_color

Background color.

property border

Border color.

property color

Text color.

native: pyqtgraph.graphicsItems.LegendItem.LegendItem
property size: int

Text size.

class magicclass.ext.pyqtgraph.components.Region[source]

Bases: magicclass.ext.pyqtgraph.components.GraphicComponent

A linear region with magicgui-like API

changed

Declares a signal emitter on a class.

This is class implements the [descriptor protocol](https://docs.python.org/3/howto/descriptor.html#descriptorhowto) and is designed to be used as a class attribute, with the supported signature types provided in the contructor:

```python from psygnal import Signal

class MyEmitter:

changed = Signal(int)

def receiver(arg: int):

print("new value:", arg)

emitter = MyEmitter() emitter.changed.connect(receiver) emitter.changed.emit(1) # prints 'new value: 1' ```

!!! note

in the example above, MyEmitter.changed is an instance of Signal, and emitter.changed is an instance of SignalInstance. See the documentation on [SignalInstance][psygnal.SignalInstance] for details on how to connect to and/or emit a signal on an instance of an object that has a Signal.

Parameters
  • *types (Union[Type[Any], Signature]) -- A sequence of individual types, or a single [inspect.Signature][] object.

  • description (str) -- Optional descriptive text for the signal. (not used internally).

  • name (Optional[str]) -- Optional name of the signal. If it is not specified then the name of the class attribute that is bound to the signal will be used. default None

  • check_nargs_on_connect (bool) -- Whether to check the number of positional args against signature when connecting a new callback. This can also be provided at connection time using .connect(..., check_nargs=True). By default, True.

  • check_types_on_connect (bool) -- Whether to check the callback parameter types against signature when connecting a new callback. This can also be provided at connection time using .connect(..., check_types=True). By default, False.

property color
property enabled: bool
native: pyqtgraph.graphicsItems.LinearRegionItem.LinearRegionItem
property value: tuple[float, float]

Get the limits of linear region.

class magicclass.ext.pyqtgraph.components.Roi(pos=(0, 0))[source]

Bases: magicclass.ext.pyqtgraph.components.GraphicComponent

property border
native: pyqtgraph.graphicsItems.ROI.ROI
class magicclass.ext.pyqtgraph.components.ScaleBar[source]

Bases: magicclass.ext.pyqtgraph.components.GraphicComponent

A scale bar with napari-like API

property color
native: pyqtgraph.graphicsItems.ScaleBar.ScaleBar
property unit: str
class magicclass.ext.pyqtgraph.components.TextItem(text: str, color: Sequence[float] | str, anchor=(0, 0), angle: float = 0)[source]

Bases: magicclass.ext.pyqtgraph.components.GraphicComponent

A text item with napari-like API.

property anchor: numpy.ndarray
property background_color
property border
property color
native: pyqtgraph.graphicsItems.TextItem.TextItem
property pos: numpy.ndarray
property text

magicclass.ext.pyqtgraph.graph_items module

class magicclass.ext.pyqtgraph.graph_items.BarPlot(x, y, face_color=None, edge_color=None, width: float = 0.6, name: str | None = None, lw: float = 1, ls: str = '-')[source]

Bases: magicclass.ext.pyqtgraph.graph_items.PlotDataLayer

property edge_color: numpy.ndarray

Edge color of the data.

property face_color: numpy.ndarray

Face color of the data.

native: pg.BarGraphItem
property xdata: numpy.ndarray
property ydata: numpy.ndarray
class magicclass.ext.pyqtgraph.graph_items.Curve(x, y, face_color=None, edge_color=None, size: float = 7, name: str | None = None, lw: float = 1, ls: str = '-', symbol=None)[source]

Bases: magicclass.ext.pyqtgraph.graph_items.PlotDataLayer

property edge_color: numpy.ndarray

Edge color of the data.

property face_color: numpy.ndarray

Face color of the data.

native: pg.PlotDataItem
property size
property symbol
class magicclass.ext.pyqtgraph.graph_items.FillBetween(x, y1, y2, face_color=None, edge_color=None, name: str | None = None, lw: float = 1, ls: str = '-')[source]

Bases: magicclass.ext.pyqtgraph.graph_items.PlotDataLayer

property edge_color: numpy.ndarray

Edge color of the data.

property face_color: numpy.ndarray

Face color of the data.

property linestyle

Line style.

property linewidth

Line width.

property ls

Line style.

property lw

Line width.

property name: str
native: pg.FillBetweenItem
class magicclass.ext.pyqtgraph.graph_items.Histogram(data, bins: int | Sequence | str = 10, range=None, density: bool = False, face_color=None, edge_color=None, name: str | None = None, lw: float = 1, ls: str = '-')[source]

Bases: magicclass.ext.pyqtgraph.graph_items.PlotDataLayer

native: pg.ScatterPlotItem
set_hist(data, bins=10, range=None, density=False)[source]
class magicclass.ext.pyqtgraph.graph_items.InfLine(pos, angle, edge_color=None, name: str | None = None, lw: float = 1, ls: str = '-')[source]

Bases: magicclass.ext.pyqtgraph.graph_items.LayerItem

property angle: float

Angle of the line in degree.

property color: numpy.ndarray
property edge_color: numpy.ndarray
property intercept: float

Y-intercept of the line.

property linestyle

Line style.

property linewidth

Line width.

property ls

Line style.

property lw

Line width.

property name
native: pyqtgraph.graphicsItems.InfiniteLine.InfiniteLine
property pos: numpy.ndarray
property slope: float

Slope of the line.

class magicclass.ext.pyqtgraph.graph_items.LayerItem[source]

Bases: object

native: pyqtgraph.graphicsItems.GraphicsItem.GraphicsItem
property visible

Visibility of data.

property zorder: float

Z-order of item. Item with larger z will be displayed on the top.

class magicclass.ext.pyqtgraph.graph_items.PlotDataLayer[source]

Bases: magicclass.ext.pyqtgraph.graph_items.LayerItem

add(points: np.ndarray | Sequence, **kwargs)[source]

Add new points to the plot data item.

property color
property edge_color: numpy.ndarray

Edge color of the data.

property face_color: numpy.ndarray

Face color of the data.

property linestyle

Line style.

property linewidth

Line width.

property ls

Line style.

property lw

Line width.

property name: str
native: pg.PlotCurveItem | pg.ScatterPlotItem
property ndata: int
remove(i: int | Sequence[int])[source]

Remove the i-th data.

property xdata: numpy.ndarray
property ydata: numpy.ndarray
class magicclass.ext.pyqtgraph.graph_items.Scatter(x, y, face_color=None, edge_color=None, size: float = 7, name: str | None = None, lw: float = 1, ls: str = '-', symbol='o')[source]

Bases: magicclass.ext.pyqtgraph.graph_items.PlotDataLayer

native: pg.ScatterPlotItem
property size
property symbol
class magicclass.ext.pyqtgraph.graph_items.TextGroup(x: Sequence[float], y: Sequence[float], texts: Sequence[str], color=None, name: Optional[str] = None)[source]

Bases: magicclass.ext.pyqtgraph.graph_items.LayerItem

property anchor: numpy.ndarray

Text anchor position.

property background_color: numpy.ndarray

Text background color.

property border: numpy.ndarray

Border color of text bounding box.

property color: numpy.ndarray

Text color.

native: pyqtgraph.graphicsItems.GraphicsItem.GraphicsItem
property text: str | list[str]

Text string.

property text_items: list[pyqtgraph.graphicsItems.TextItem.TextItem]
property xdata: numpy.ndarray
property ydata: numpy.ndarray
class magicclass.ext.pyqtgraph.graph_items.TextItemView(textitem: pg.TextItem | list[pg.TextItem])[source]

Bases: object

property anchor: numpy.ndarray

Text anchor position.

property background_color: numpy.ndarray

Text background color.

property border: numpy.ndarray

Border color of text bounding box.

property color: numpy.ndarray

Text color.

property text: str | list[str]

Text string.

magicclass.ext.pyqtgraph.mouse_event module

class magicclass.ext.pyqtgraph.mouse_event.MouseClickEvent(event: pyqtgraph.GraphicsScene.mouseEvents.MouseClickEvent, coord_item)[source]

Bases: pyqtgraph.GraphicsScene.mouseEvents.MouseClickEvent

buttons()[source]

Return the buttons currently pressed on the mouse. (see QGraphicsSceneMouseEvent::buttons in the Qt documentation)

lastPos()[source]

Return the previous position of the mouse in the coordinate system of the item that the event was delivered to.

modifiers()[source]

Return any keyboard modifiers currently pressed. (see QGraphicsSceneMouseEvent::modifiers in the Qt documentation)

pos()[source]

Return the current position of the mouse in the coordinate system of the item that the event was delivered to.

magicclass.ext.pyqtgraph.widgets module

class magicclass.ext.pyqtgraph.widgets.HasBackground(layout='vertical', **kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

property background_color
class magicclass.ext.pyqtgraph.widgets.HasDataItems[source]

Bases: object

add_bar(x: Sequence[float], **kwargs) magicclass.ext.pyqtgraph.graph_items.BarPlot[source]
add_bar(x: Sequence[float], y: Sequence[float], **kwargs) magicclass.ext.pyqtgraph.graph_items.BarPlot

Add a bar plot like plt.bar(x, y).

Parameters
  • x (array-like) --

    X data.

    y : array-like

    Y data.

  • width (float, default is 0.6) -- Width of each bar.

  • face_color (str or array-like, optional) --

    Face color of plot. Graphic object will be filled with this color.

    edge_color: str or array-like, optional

    Edge color of plot.

    color: str or array-like, optional

    Set face color and edge color at the same time.

    name: str, optional

    Object name of the plot item.

    lw: float, default is 1.0

    Line width of edge.

    ls: str, default is "-"

    Line style of edge. One of "-", "--", ":" or "-.".

Returns

A plot item of the bar plot.

Return type

BarPlot

add_curve(x: Sequence[float], **kwargs) magicclass.ext.pyqtgraph.graph_items.Curve[source]
add_curve(x: Sequence[float], y: Sequence[float], **kwargs) magicclass.ext.pyqtgraph.graph_items.Curve

Add a line plot like plt.plot(x, y).

Parameters
  • x (array-like) --

    X data.

    y : array-like

    Y data.

    face_color: str or array-like, optional

    Face color of plot. Graphic object will be filled with this color.

    edge_color: str or array-like, optional

    Edge color of plot.

    color: str or array-like, optional

    Set face color and edge color at the same time.

  • size (float, default is 7) -- Symbol size.

  • name (str, optional) --

    Object name of the plot item.

    lw: float, default is 1.0

    Line width of edge.

    ls: str, default is "-"

    Line style of edge. One of "-", "--", ":" or "-.".

    symbol: str, optional

    Symbol style. Currently supports circle ("o"), cross ("+", "x"), star ("*"), square ("s", "D") triangle ("^", "<", "v", ">") and others that pyqtgraph supports.

Returns

A plot item of a curve.

Return type

Curve

add_fillbetween(x: Sequence[float], **kwargs) magicclass.ext.pyqtgraph.graph_items.FillBetween[source]
add_fillbetween(x: Sequence[float], y: Sequence[float], **kwargs) magicclass.ext.pyqtgraph.graph_items.FillBetween
add_hist(data: Sequence[float], bins: int | Sequence | str = 10, range=None, density: bool = False, face_color=None, edge_color=None, color=None, name: str | None = None, lw: float = 1, ls: str = '-') Histogram[source]

Add histogram like plt.hist(data).

Parameters
  • data (array-like) -- Data for histogram constrction.

  • bins (int, sequence of float or str, default is 10) -- Bin numbers. See np.histogram for detail.

  • range (two floats, optional) -- Bin ranges. See np.histogram for detail.

  • density (bool, default is False) -- If true, plot the density instead of the counts. See np.histogram for detail.

  • face_color (str or array-like, optional) --

    Face color of plot. Graphic object will be filled with this color.

    edge_color: str or array-like, optional

    Edge color of plot.

    color: str or array-like, optional

    Set face color and edge color at the same time.

    name: str, optional

    Object name of the plot item.

    lw: float, default is 1.0

    Line width of edge.

    ls: str, default is "-"

    Line style of edge. One of "-", "--", ":" or "-.".

Returns

A plot item of the histogram.

Return type

Histogram

add_infline(slope: float, intercept: float, color=None, name: str | None = None, lw: float = 1, ls: str = '-') magicclass.ext.pyqtgraph.graph_items.InfLine[source]
add_infline(pos: tuple[float, float], degree: float, color=None, name: str | None = None, lw: float = 1, ls: str = '-') magicclass.ext.pyqtgraph.graph_items.InfLine
add_scatter(x: Sequence[float], **kwargs) magicclass.ext.pyqtgraph.graph_items.Scatter[source]
add_scatter(x: Sequence[float], y: Sequence[float], **kwargs) magicclass.ext.pyqtgraph.graph_items.Scatter

Add scatter plot like plt.scatter(x, y).

Parameters
  • x (array-like) --

    X data.

    y : array-like

    Y data.

    face_color: str or array-like, optional

    Face color of plot. Graphic object will be filled with this color.

    edge_color: str or array-like, optional

    Edge color of plot.

    color: str or array-like, optional

    Set face color and edge color at the same time.

  • size (float, default is 7) -- Symbol size.

  • name (str, optional) --

    Object name of the plot item.

    lw: float, default is 1.0

    Line width of edge.

    ls: str, default is "-"

    Line style of edge. One of "-", "--", ":" or "-.".

    symbol: str, optional

    Symbol style. Currently supports circle ("o"), cross ("+", "x"), star ("*"), square ("s", "D") triangle ("^", "<", "v", ">") and others that pyqtgraph supports.

Returns

A plot item of the scatter plot.

Return type

Scatter

add_text(x: float, y: float, text: str, **kwargs) magicclass.ext.pyqtgraph.graph_items.TextGroup[source]
add_text(x: Sequence[float], y: Sequence[float], text: Sequence[str], **kwargs) magicclass.ext.pyqtgraph.graph_items.TextGroup
property layers: magicclass.ext.pyqtgraph.widgets.LayerList
class magicclass.ext.pyqtgraph.widgets.HasViewBox(viewbox: pyqtgraph.graphicsItems.ViewBox.ViewBox.ViewBox)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasDataItems

property border
property enabled: bool

Mouse interactivity

property interactive: bool

Mouse interactivity

property xlim

Range limits of X-axis.

property ylim

Range limits of Y-axis.

class magicclass.ext.pyqtgraph.widgets.ImageItem(viewbox: pg.ViewBox | None = None, lock_contrast_limits: bool = False)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasViewBox

property cmap

Color map

property contrast_limits: list[float, float]

Contrast limits of image

property image: np.ndarray | None

Image data

property lock_contrast_limits

True if enable auto-contrast.

property scale_bar: magicclass.ext.pyqtgraph.components.ScaleBar

Scale bar on the image.

property text_overlay: magicclass.ext.pyqtgraph.components.TextItem

Text overlay on the image.

property title: str

Title text of the graph.

property xlabel: str

Label of X-axis.

property ylabel: str

Label of X-axis.

class magicclass.ext.pyqtgraph.widgets.LayerList(parent: magicclass.ext.pyqtgraph.widgets.HasDataItems)[source]

Bases: MutableSequence[magicclass.ext.pyqtgraph.graph_items.LayerItem]

A napari-like layer list for plot item handling.

append(item: magicclass.ext.pyqtgraph.graph_items.LayerItem)[source]

S.append(value) -- append value to the end of the sequence

clear() None -- remove all items from S[source]
insert(pos: int, item: magicclass.ext.pyqtgraph.graph_items.LayerItem)[source]

S.insert(index, value) -- insert value before index

move(source: int, destination: int)[source]
swap(pos0: int, pos1: int)[source]
class magicclass.ext.pyqtgraph.widgets.PlotItem(viewbox: pg.ViewBox | None = None)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasViewBox

A 1-D plot item that has similar API as napari Viewer.

property legend: magicclass.ext.pyqtgraph.components.Legend

Legend item.

property region: magicclass.ext.pyqtgraph.components.Region

Linear region item.

property title: str

Title text of the graph.

property xlabel: str

Label of X-axis.

property ylabel: str

Label of Y-axis.

class magicclass.ext.pyqtgraph.widgets.Qt2YPlotCanvas(**kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasBackground

A plot canvas with two Y-axis.

updateViews()[source]
class magicclass.ext.pyqtgraph.widgets.QtImageCanvas(lock_contrast_limits: bool = False, **kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasBackground, magicclass.ext.pyqtgraph.widgets.ImageItem

A 2-D image viewer that have similar API as napari Viewer.

property background_color
class magicclass.ext.pyqtgraph.widgets.QtMultiImageCanvas(nrows: int = 1, ncols: int = 1, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets._MultiPlot[magicclass.ext.pyqtgraph.widgets.ImageItem]

A pyqtgraph-based canvas with multiple images.

class magicclass.ext.pyqtgraph.widgets.QtMultiPlotCanvas(nrows: int = 1, ncols: int = 1, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets._MultiPlot[magicclass.ext.pyqtgraph.widgets.PlotItem]

A pyqtgraph-based canvas with multiple plot.

class magicclass.ext.pyqtgraph.widgets.QtPlotCanvas(**kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasBackground, magicclass.ext.pyqtgraph.widgets.PlotItem

A 1-D data viewer that have similar API as napari Viewer.

class magicclass.ext.pyqtgraph.widgets.SimpleViewBox[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasViewBox

class magicclass.ext.pyqtgraph.widgets.ViewBoxExt(parent=None, border=None, lockAspect=False, enableMouse=True, invertY=False, enableMenu=True, name=None, invertX=False, defaultPadding=0.02)[source]

Bases: pyqtgraph.graphicsItems.ViewBox.ViewBox.ViewBox

hoverEvent(ev)[source]

Module contents

PyQtGraph wrapper classes. Currently supports QtPlotCanvas, QtMultiPlotCanvas, Qt2YPlotCanvas, QtImageCanvas, QtMultiImageCanvas and PYQTGRAPH_AVAILABLE.

These classes offer unified API between graphical items and components, similar to those in magicgui and napari.

QtPlotCanvas can treat line plot, scatter plot, bar plot and histogram as "layers".

from magicclass.widgets import QtPlotCanvas

canvas = QtPlotCanvas()
canvas.add_curve(np.random.random(100), color="r") # like plt.plot
canvas.add_scatter(np.random.random(100), ls=":")  # like plt.scatter
canvas.layers[1].visible = False  # toggle visibility
canvas.enabled = False            # toggle interactivity
canvas.show()

Other components such as axis labels, title and linear region have intuitive interface.

canvas.region.visible = True  # show linear region
canvas.region.value           # get range
canvas.xlabel = "time"        # change label text
canvas.xlim = [0, 1]          # change limits.

QtImageCanvas is also designed in a similar way as QtPlotCanvas but aims at 2D image visualization.

from magicclass.widgets import QtImageCanvas

canvas = QtImageCanvas()
canvas.image = np.random.random((128, 128))
canvas.show()

Text overlay and scale bar are available now.

canvas.text_overlay.text = "some info"
canvas.text_overlay.color = "lime"
canvas.scale_bar.unit = "px"
canvas.scale_bar.visible = True
class magicclass.ext.pyqtgraph.Qt2YPlotCanvas(**kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasBackground

A plot canvas with two Y-axis.

updateViews()[source]
class magicclass.ext.pyqtgraph.QtImageCanvas(lock_contrast_limits: bool = False, **kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasBackground, magicclass.ext.pyqtgraph.widgets.ImageItem

A 2-D image viewer that have similar API as napari Viewer.

property background_color
class magicclass.ext.pyqtgraph.QtMultiImageCanvas(nrows: int = 1, ncols: int = 1, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets._MultiPlot[magicclass.ext.pyqtgraph.widgets.ImageItem]

A pyqtgraph-based canvas with multiple images.

class magicclass.ext.pyqtgraph.QtMultiPlotCanvas(nrows: int = 1, ncols: int = 1, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets._MultiPlot[magicclass.ext.pyqtgraph.widgets.PlotItem]

A pyqtgraph-based canvas with multiple plot.

class magicclass.ext.pyqtgraph.QtPlotCanvas(**kwargs)[source]

Bases: magicclass.ext.pyqtgraph.widgets.HasBackground, magicclass.ext.pyqtgraph.widgets.PlotItem

A 1-D data viewer that have similar API as napari Viewer.