magicclass.widgets.qtgraph package

Submodules

magicclass.widgets.qtgraph.components module

class magicclass.widgets.qtgraph.components.GraphicComponent[source]

Bases: object

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

Linear region visibility.

class magicclass.widgets.qtgraph.components.Legend(offset=(0, 0))[source]

Bases: magicclass.widgets.qtgraph.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.widgets.qtgraph.components.Region[source]

Bases: magicclass.widgets.qtgraph.components.GraphicComponent

A linear region with magicgui-like API

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

Get the limits of linear region.

class magicclass.widgets.qtgraph.components.Roi(pos=(0, 0))[source]

Bases: magicclass.widgets.qtgraph.components.GraphicComponent

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

Bases: magicclass.widgets.qtgraph.components.GraphicComponent

A scale bar with napari-like API

property color
native: pyqtgraph.graphicsItems.ScaleBar.ScaleBar
property unit: str
class magicclass.widgets.qtgraph.components.TextOverlay(text: str, color: Sequence[float] | str)[source]

Bases: magicclass.widgets.qtgraph.components.GraphicComponent

A text overlay with napari-like API.

property background_color
property border
property color
native: pyqtgraph.graphicsItems.TextItem.TextItem
property text

magicclass.widgets.qtgraph.graph_items module

class magicclass.widgets.qtgraph.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.widgets.qtgraph.graph_items.PlotDataItem

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.widgets.qtgraph.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.widgets.qtgraph.graph_items.PlotDataItem

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.widgets.qtgraph.graph_items.FillBetween(x, y1, y2, face_color=None, edge_color=None, name: str | None = None, lw: float = 1, ls: str = '-')[source]

Bases: magicclass.widgets.qtgraph.graph_items.PlotDataItem

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.widgets.qtgraph.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.widgets.qtgraph.graph_items.PlotDataItem

native: pg.ScatterPlotItem
set_hist(data, bins=10, range=None, density=False)[source]
class magicclass.widgets.qtgraph.graph_items.PlotDataItem[source]

Bases: object

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 visible

Visibility of data.

property xdata: numpy.ndarray
property ydata: numpy.ndarray
property zorder: float

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

class magicclass.widgets.qtgraph.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.widgets.qtgraph.graph_items.PlotDataItem

native: pg.ScatterPlotItem
property size
property symbol

magicclass.widgets.qtgraph.mouse_event module

class magicclass.widgets.qtgraph.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.widgets.qtgraph.qt_graph module

class magicclass.widgets.qtgraph.qt_graph.HasDataItems[source]

Bases: object

add_bar(x: Sequence[float], **kwargs)[source]
add_bar(x: Sequence[float], y: Sequence[float], **kwargs)

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)[source]
add_curve(x: Sequence[float], y: Sequence[float], **kwargs)

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)[source]
add_fillbetween(x: Sequence[float], y: Sequence[float], **kwargs)
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 = '-')[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_scatter(x: Sequence[float], **kwargs)[source]
add_scatter(x: Sequence[float], y: Sequence[float], **kwargs)

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

property layers: magicclass.widgets.qtgraph.qt_graph.LayerList
class magicclass.widgets.qtgraph.qt_graph.HasViewBox(viewbox: pyqtgraph.graphicsItems.ViewBox.ViewBox.ViewBox)[source]

Bases: magicclass.widgets.qtgraph.qt_graph.HasDataItems

property background_color
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.widgets.qtgraph.qt_graph.ImageItem(viewbox: pg.ViewBox | None = None, lock_contrast_limits: bool = False)[source]

Bases: magicclass.widgets.qtgraph.qt_graph.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
property scale_bar: magicclass.widgets.qtgraph.components.ScaleBar

Scale bar on the image.

property text_overlay: magicclass.widgets.qtgraph.components.TextOverlay

Text overlay on the image.

class magicclass.widgets.qtgraph.qt_graph.LayerList(parent: magicclass.widgets.qtgraph.qt_graph.HasDataItems)[source]

Bases: MutableSequence[magicclass.widgets.qtgraph.graph_items.PlotDataItem]

A napari-like layer list for plot item handling.

append(item: magicclass.widgets.qtgraph.graph_items.PlotDataItem)[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.widgets.qtgraph.graph_items.PlotDataItem)[source]

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

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

Bases: magicclass.widgets.qtgraph.qt_graph.HasViewBox

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

property legend: magicclass.widgets.qtgraph.components.Legend

Legend item.

property region: magicclass.widgets.qtgraph.components.Region

Linear region item.

property title: str
property xlabel

Label of X-axis.

property ylabel: str

Label of Y-axis.

class magicclass.widgets.qtgraph.qt_graph.Qt2YPlotCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

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

Bases: magicclass.widgets.utils.FreeWidget, magicclass.widgets.qtgraph.qt_graph.ImageItem

class magicclass.widgets.qtgraph.qt_graph.QtMultiImageCanvas(nrows: int = 0, ncols: int = 0, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.widgets.qtgraph.qt_graph._MultiPlot[magicclass.widgets.qtgraph.qt_graph.ImageItem]

A pyqtgraph-based canvas with multiple images.

class magicclass.widgets.qtgraph.qt_graph.QtMultiPlotCanvas(nrows: int = 0, ncols: int = 0, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.widgets.qtgraph.qt_graph._MultiPlot[magicclass.widgets.qtgraph.qt_graph.PlotItem]

A pyqtgraph-based canvas with multiple plot.

class magicclass.widgets.qtgraph.qt_graph.QtPlotCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.widgets.qtgraph.qt_graph.PlotItem

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

class magicclass.widgets.qtgraph.qt_graph.SimpleViewBox[source]

Bases: magicclass.widgets.qtgraph.qt_graph.HasViewBox

class magicclass.widgets.qtgraph.qt_graph.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 and QtMultiImageCanvas.

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.widgets.qtgraph.Qt2YPlotCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

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

Bases: magicclass.widgets.utils.FreeWidget, magicclass.widgets.qtgraph.qt_graph.ImageItem

class magicclass.widgets.qtgraph.QtMultiImageCanvas(nrows: int = 0, ncols: int = 0, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.widgets.qtgraph.qt_graph._MultiPlot[magicclass.widgets.qtgraph.qt_graph.ImageItem]

A pyqtgraph-based canvas with multiple images.

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

Bases: magicclass.widgets.qtgraph.qt_graph._MultiPlot[magicclass.widgets.qtgraph.qt_graph.PlotItem]

A pyqtgraph-based canvas with multiple plot.

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

Bases: magicclass.widgets.utils.FreeWidget, magicclass.widgets.qtgraph.qt_graph.PlotItem

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