magicclass.ext.pyqtgraph package¶
Subpackages¶
Submodules¶
magicclass.ext.pyqtgraph.components module¶
- class magicclass.ext.pyqtgraph.components.GraphicComponent[source]¶
Bases:
object
- native: GraphicsObject¶
- property visible: bool¶
Linear region visibility.
- class magicclass.ext.pyqtgraph.components.Legend(offset=(0, 0))[source]¶
Bases:
GraphicComponent
- property background_color¶
Background color.
- property border¶
Border color.
- property color¶
Text color.
- native: LegendItem¶
- property size: int¶
Text size.
- class magicclass.ext.pyqtgraph.components.Region[source]¶
Bases:
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: LinearRegionItem¶
- property value: tuple[float, float]¶
Get the limits of linear region.
- class magicclass.ext.pyqtgraph.components.Roi(pos=(0, 0))[source]¶
Bases:
GraphicComponent
- property border¶
- native: ROI¶
- class magicclass.ext.pyqtgraph.components.ScaleBar[source]¶
Bases:
GraphicComponent
A scale bar with napari-like API
- property color¶
- native: ScaleBar¶
- property unit: str¶
- class magicclass.ext.pyqtgraph.components.TextItem(text: str, color: Sequence[float] | str, anchor=(0, 0), angle: float = 0)[source]¶
Bases:
GraphicComponent
A text item with napari-like API.
- property anchor: ndarray¶
- property background_color¶
- property border¶
- property color¶
- native: TextItem¶
- property pos: 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:
PlotDataLayer
- property edge_color: ndarray¶
Edge color of the data.
- property face_color: ndarray¶
Face color of the data.
- native: pg.BarGraphItem¶
- property xdata: ndarray¶
- property ydata: 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:
PlotDataLayer
- property edge_color: ndarray¶
Edge color of the data.
- property face_color: 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:
PlotDataLayer
- property edge_color: ndarray¶
Edge color of the data.
- property face_color: 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:
PlotDataLayer
- native: pg.ScatterPlotItem¶
- class magicclass.ext.pyqtgraph.graph_items.InfLine(pos, angle, edge_color=None, name: str | None = None, lw: float = 1, ls: str = '-')[source]¶
Bases:
LayerItem
- property angle: float¶
Angle of the line in degree.
- property color: ndarray¶
- property edge_color: 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: InfiniteLine¶
- property pos: ndarray¶
- property slope: float¶
Slope of the line.
- class magicclass.ext.pyqtgraph.graph_items.LayerItem[source]¶
Bases:
object
- native: 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:
LayerItem
- property color¶
- property edge_color: ndarray¶
Edge color of the data.
- property face_color: 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¶
- property xdata: ndarray¶
- property ydata: 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:
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:
LayerItem
- property anchor: ndarray¶
Text anchor position.
- property background_color: ndarray¶
Text background color.
- property border: ndarray¶
Border color of text bounding box.
- property color: ndarray¶
Text color.
- native: GraphicsItem¶
- property text: str | list[str]¶
Text string.
- property text_items: list[pyqtgraph.graphicsItems.TextItem.TextItem]¶
- property xdata: ndarray¶
- property ydata: ndarray¶
- class magicclass.ext.pyqtgraph.graph_items.TextItemView(textitem: pg.TextItem | list[pg.TextItem])[source]¶
Bases:
object
- property anchor: ndarray¶
Text anchor position.
- property background_color: ndarray¶
Text background color.
- property border: ndarray¶
Border color of text bounding box.
- property color: ndarray¶
Text color.
- property text: str | list[str]¶
Text string.
magicclass.ext.pyqtgraph.mouse_event module¶
- class magicclass.ext.pyqtgraph.mouse_event.MouseClickEvent(event: MouseClickEvent, coord_item)[source]¶
Bases:
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.
magicclass.ext.pyqtgraph.plot_api module¶
- magicclass.ext.pyqtgraph.plot_api.plot(x=None, y=None, face_color=None, edge_color=None, color=None, size: float = 7, name: str | None = None, lw: float = 1, ls: str = '-', symbol=None) QtPlotCanvas [source]¶
- magicclass.ext.pyqtgraph.plot_api.scatter(x=None, y=None, face_color=None, edge_color=None, color=None, size: float = 7, name: str | None = None, symbol=None) QtPlotCanvas [source]¶
magicclass.ext.pyqtgraph.widgets module¶
- class magicclass.ext.pyqtgraph.widgets.HasBackground(layout='vertical', **kwargs)[source]¶
Bases:
FreeWidget
- property background_color¶
- class magicclass.ext.pyqtgraph.widgets.HasDataItems[source]¶
Bases:
object
- add_bar(x: Sequence[float], **kwargs) BarPlot [source]¶
- add_bar(x: Sequence[float], y: Sequence[float], **kwargs) 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
- add_curve(x: Sequence[float], **kwargs) Curve [source]¶
- add_curve(x: Sequence[float], y: Sequence[float], **kwargs) 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
- add_fillbetween(x: Sequence[float], **kwargs) FillBetween [source]¶
- add_fillbetween(x: Sequence[float], y: Sequence[float], **kwargs) 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
- add_infline(slope: float, intercept: float, color=None, name: str | None = None, lw: float = 1, ls: str = '-') InfLine [source]¶
- add_infline(pos: tuple[float, float], degree: float, color=None, name: str | None = None, lw: float = 1, ls: str = '-') InfLine
- add_scatter(x: Sequence[float], **kwargs) Scatter [source]¶
- add_scatter(x: Sequence[float], y: Sequence[float], **kwargs) 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
- class magicclass.ext.pyqtgraph.widgets.HasViewBox(viewbox: ViewBox)[source]¶
Bases:
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:
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 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: HasDataItems)[source]¶
Bases:
MutableSequence
[LayerItem
]A napari-like layer list for plot item handling.
- class magicclass.ext.pyqtgraph.widgets.PlotItem(viewbox: pg.ViewBox | None = None)[source]¶
Bases:
HasViewBox
A 1-D plot item that has similar API as napari Viewer.
- 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:
HasBackground
A plot canvas with two Y-axis.
- class magicclass.ext.pyqtgraph.widgets.QtImageCanvas(lock_contrast_limits: bool = False, **kwargs)[source]¶
Bases:
HasBackground
,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:
_MultiPlot
[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:
_MultiPlot
[PlotItem
]A pyqtgraph-based canvas with multiple plot.
- class magicclass.ext.pyqtgraph.widgets.QtPlotCanvas(**kwargs)[source]¶
Bases:
HasBackground
,PlotItem
A 1-D data viewer that have similar API as napari Viewer.
- class magicclass.ext.pyqtgraph.widgets.SimpleViewBox[source]¶
Bases:
HasViewBox
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:
HasBackground
A plot canvas with two Y-axis.
- class magicclass.ext.pyqtgraph.QtImageCanvas(lock_contrast_limits: bool = False, **kwargs)[source]¶
Bases:
HasBackground
,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:
_MultiPlot
[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:
_MultiPlot
[PlotItem
]A pyqtgraph-based canvas with multiple plot.
- class magicclass.ext.pyqtgraph.QtPlotCanvas(**kwargs)[source]¶
Bases:
HasBackground
,PlotItem
A 1-D data viewer that have similar API as napari Viewer.