Reference¶
Base classes¶
- class plotpy.tools.base.GuiTool(manager: PlotManager, toolbar_id: Any | type[DefaultToolbarID] | None = <class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
Base class for interactive tool applying on a plot
- Parameters:
manager – plot manager
toolbar_id – toolbar ID
- create_action(manager: PlotManager) QW.QAction | None [source]¶
Create and return tool’s action
- Parameters:
manager – plot manager
- Returns:
Tool’s action or None (if tool has no action)
Create and return menu for the tool’s action
- Parameters:
manager – plot manager
- set_parent_tool(tool: GuiToolT) None [source]¶
Used to organize tools automatically in menu items
- Parameters:
tool – parent tool
- register_plot(baseplot: BasePlot) None [source]¶
Every BasePlot using this tool should call register_plot to notify the tool about this widget using it
- Parameters:
baseplot – base plot
- get_active_plot() BasePlot | None [source]¶
Return the currently active BasePlot or None if no plot is active
- update_status(plot: BasePlot) None [source]¶
Update the status of the tool based on the currently active plot
Can also be called after an action modifying the BasePlot (e.g. in order to update action states when an item is deselected)
- Parameters:
plot – base plot
If the tool supports it, this method should install an action in the context menu
- Parameters:
menu – context menu
plot – base plot
- class plotpy.tools.InteractiveTool(manager: PlotManager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Interactive tool base class
- Parameters:
manager – plot manager
toolbar_id – toolbar ID
title – tool title
icon – tool icon
tip – tool tip
switch_to_default_tool – switch to default tool when finished
- SIG_VALIDATE_TOOL(PyQt_PyObject)¶
Signal emitted by InteractiveTool when validating tool action
- SIG_TOOL_JOB_FINISHED¶
Signal emitted by InteractiveTool when tool job is finished
- create_action(manager: PlotManager) QW.QAction [source]¶
Create and return tool’s action
- Parameters:
manager – plot manager
- Returns:
Tool’s action
- cursor() CursorShape [source]¶
Return tool mouse cursor shape
- interactive_triggered(action: QAction) None [source]¶
Slot called when the interactive tool action group is triggered. The purpose is to deactivate all other tools in the group.
Note that the tool itself has already been activated because the action triggered the activate method.
- Parameters:
action – tool action
- validate(filter: StatefulEventFilter, event: QEvent) None [source]¶
Validate tool action
- Parameters:
filter – event filter
event – event
- class plotpy.tools.CommandTool(manager: PlotManager, title: str, icon: str | None = None, tip: str | None = None, toolbar_id: Any | type[DefaultToolbarID] | None = <class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
Base class for command tools: action, context menu entry
- Parameters:
manager – plot manager
title – tool title
icon – tool icon
tip – tool tip
toolbar_id – toolbar ID
- create_action(manager: PlotManager) QW.QAction [source]¶
Create and return tool’s action
- Parameters:
manager – plot manager
- Returns:
Tool’s action
Setup context menu
- Parameters:
menu – context menu
plot – base plot
- class plotpy.tools.ActionTool(manager: PlotManager, action: QW.QAction, item_types: Any | None = None, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
Tool that simply associate an action to a tool
- Parameters:
manager – plot manager
action – action
item_types – item types
toolbar_id – toolbar ID
- update_status(plot: BasePlot) None [source]¶
Update the status of the tool based on the currently active plot
Can also be called after an action modifying the BasePlot (e.g. in order to update action states when an item is deselected)
- Parameters:
plot – base plot
- create_action(manager: PlotManager) QW.QAction [source]¶
Create and return tool’s action
- Parameters:
manager – plot manager
- Returns:
Tool’s action
Plot tools¶
- class plotpy.tools.DoAutoscaleTool(manager, title='AutoScale', icon='autoscale.png', tip=None, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
A tool to perform autoscale for associated plot.
Set up the context menu for the tool.
- Parameters:
menu – Context menu
plot – Plot instance
- class plotpy.tools.DisplayCoordsTool(manager)[source]¶
Tool for displaying coordinates.
Create and return menu for the tool’s action.
- Parameters:
manager – Plot manager
- Returns:
Menu for the tool’s action
- activate_canvas_pointer(enable: bool) None [source]¶
Activate canvas pointer.
- Parameters:
enable – Whether to enable the canvas pointer
- class plotpy.tools.RectZoomTool(manager: PlotManager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Item tools¶
- class plotpy.tools.SelectTool(manager: PlotManager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Graphical Object Selection Tool
- setup_filter(baseplot: BasePlot) int [source]¶
Set up the event filter for the tool.
- Parameters:
baseplot – Base plot instance
- Returns:
Start state of the filter
- select_all_items(filter: StatefulEventFilter, event: QEvent) None [source]¶
Select all items in the plot.
- Parameters:
filter – Event filter
event – Event that triggered the selection
- move_with_arrow(filter: StatefulEventFilter, event: QKeyEvent) None [source]¶
Move selected items with arrow keys.
- Parameters:
filter – Event filter
event – Key event
- rotate_with_arrow(filter: StatefulEventFilter, event: QKeyEvent) None [source]¶
Rotate selected items with arrow keys.
- Parameters:
filter – Event filter
event – Key event
- class plotpy.tools.ItemListPanelTool(manager: PlotManager)[source]¶
Tool for managing the item list panel.
- class plotpy.tools.SaveItemsTool(manager, toolbar_id: str | type[~plotpy.tools.base.DefaultToolbarID] = <class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
- class plotpy.tools.LoadItemsTool(manager, toolbar_id: str | type[~plotpy.tools.base.DefaultToolbarID] = <class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
- class plotpy.tools.ExportItemDataTool(manager, toolbar_id: str | type[DefaultToolbarID] | None = None)[source]¶
Tool for exporting item data.
- class plotpy.tools.EditItemDataTool(manager, toolbar_id: str | type[DefaultToolbarID] | None = None)[source]¶
Tool for editing item data.
- class plotpy.tools.ItemCenterTool(manager, toolbar_id: str | type[DefaultToolbarID] | None = None)[source]¶
Tool for centering items.
- get_supported_items(plot: BasePlot) list [source]¶
Get supported items from the plot.
- Parameters:
plot – Plot instance
- Returns:
List of supported plot items
- class plotpy.tools.DeleteItemTool(manager, toolbar_id: str | type[DefaultToolbarID] | None = None)[source]¶
- get_removable_items(plot: BasePlot) list [source]¶
Get removable items from the plot.
- Parameters:
plot – Plot instance
- Returns:
List of removable plot items
Shape tools¶
- class plotpy.tools.MultiLineTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
A tool for drawing multi-line shapes (polylines) on a plot.
This tool allows users to create polyline shapes by clicking on the plot to add points. The shape can be finalized using the Enter or Space key.
- Parameters:
manager – The plot manager.
handle_final_shape_cb – Callback function to handle the final shape.
shape_style – Tuple containing the style section and key for the shape.
toolbar_id – ID of the toolbar to which this tool belongs.
title – Title of the tool.
icon – Icon for the tool.
tip – Tooltip for the tool.
switch_to_default_tool – Whether to switch to the default tool after use.
- set_shape_style(shape: PolygonShape) None [source]¶
Set shape style
- Parameters:
shape – shape
- create_shape() PolygonShape [source]¶
Create shape
- setup_shape(shape: PolygonShape) None [source]¶
Setup shape
- get_shape() PolygonShape [source]¶
Get shape
- Returns:
shape
- setup_filter(baseplot: BasePlot) StatefulEventFilter [source]¶
Set up the event filter for the tool.
- Parameters:
baseplot – The base plot object.
- Returns:
The configured filter.
- end_polyline(filter: StatefulEventFilter, points: ndarray) None [source]¶
End the polyline and reset the tool.
- Parameters:
filter – The plot filter.
points – The points of the polyline.
- class plotpy.tools.PolygonTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
A tool for drawing free-form shapes on a plot.
This tool extends the MultiLineTool to create closed shapes when there are more than 2 points.
- class plotpy.tools.LabelTool(manager, handle_label_cb=None, label_style=None, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>, title=None, icon=None, tip=None, switch_to_default_tool=None)[source]¶
- class plotpy.tools.RectangularShapeTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Base class for tools that create rectangular shapes.
- Parameters:
manager – The plot manager.
setup_shape_cb – Callback function to set up the shape.
handle_final_shape_cb – Callback function to handle the final shape.
shape_style – Tuple containing the style section and key for the shape.
toolbar_id – ID of the toolbar to which this tool belongs.
title – Title of the tool.
icon – Icon for the tool.
tip – Tooltip for the tool.
switch_to_default_tool – Whether to switch to the default tool after use.
- add_shape_to_plot(plot, p0: QPointF, p1: QPointF)[source]¶
Add the final shape to the plot.
- Parameters:
plot – The plot object.
p0 – The first point of the shape.
p1 – The second point of the shape.
- class plotpy.tools.RectangleTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating rectangle shapes.
- class plotpy.tools.PointTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating point shapes.
- class plotpy.tools.SegmentTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating segment shapes.
- class plotpy.tools.CircleTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating circle shapes.
- class plotpy.tools.EllipseTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating ellipse shapes.
- class plotpy.tools.AnnotatedRectangleTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating annotated rectangle shapes.
This tool extends the RectangleTool to create AnnotatedRectangle objects.
- class plotpy.tools.AnnotatedCircleTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating annotated circle shapes.
This tool extends the CircleTool to create AnnotatedCircle objects.
- class plotpy.tools.AnnotatedEllipseTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating annotated ellipse shapes.
This tool extends the EllipseTool to create AnnotatedEllipse objects.
- class plotpy.tools.AnnotatedPointTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating annotated point shapes.
This tool extends the PointTool to create AnnotatedPoint objects.
- class plotpy.tools.AnnotatedSegmentTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating annotated segment shapes.
This tool extends the SegmentTool to create AnnotatedSegment objects.
- class plotpy.tools.AnnotatedPolygonTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
Tool for creating annotated polygon shapes.
This tool extends the PolygonTool to create AnnotatedPolygon objects.
- create_shape() AnnotatedPolygon [source]¶
Create an annotated polygon shape.
- Returns:
A tuple containing the AnnotatedPolygon object and its handle indices.
Curve tools¶
- class plotpy.tools.CurveStatsTool(manager: PlotManager, labelfuncs: tuple[tuple[str, Callable[..., Any]], ...] | None = None, toolbar_id: Any = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None)[source]¶
Curve statistics tool
- Parameters:
manager – PlotManager Instance
toolbar_id – Toolbar Id to use. Defaults to DefaultToolbarID.
title – Tool name. Defaults to None.
icon – Tool icon path. Defaults to None.
tip – Available tip. Defaults to None.
switch_to_default_tool – Wether to use as the default tool or not. Defaults to None.
- set_labelfuncs(labelfuncs: tuple[tuple[str, Callable[[...], Any]], ...]) None [source]¶
Set label functions
- Parameters:
labelfuncs – Label functions
Example
labelfuncs = ( ("%g < x < %g", lambda *args: (args[0].min(), args[0].max())), ("%g < y < %g", lambda *args: (args[1].min(), args[1].max())), ("<y>=%g", lambda *args: args[1].mean()), ("σ(y)=%g", lambda *args: args[1].std()), ("∑(y)=%g", lambda *args: spt.trapezoid(args[1])), ("∫ydx=%g", lambda *args: spt.trapezoid(args[1], args[0])), )
- create_shape() XRangeSelection [source]¶
Create shape associated with the tool
- create_label() DataInfoLabel [source]¶
Create label associated with the tool
- move(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Move tool action
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- end_move(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
End shape move
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- class plotpy.tools.SelectPointTool(manager: PlotManager, mode: str = 'reuse', on_active_item: bool = False, title: str | None = None, icon: str | None = None, tip: str | None = None, end_callback: Callable[[SelectPointTool], Any] | None = None, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>, marker_style=None, switch_to_default_tool=None)[source]¶
Curve point selection tool
- Parameters:
manager – PlotManager Instance
mode – Selection mode. Defaults to “reuse”.
on_active_item – Wether to use the active item or not. Defaults to False.
title – Tool name. Defaults to None.
icon – Tool icon path. Defaults to None.
tip – Available tip. Defaults to None.
end_callback – Callback function taking a Self instance as argument that will be passed when the user stops dragging the point. Defaults to None.
toolbar_id – Toolbar Id to use. Defaults to DefaultToolbarID.
marker_style – Marker style. Defaults to None.
switch_to_default_tool – Wether to use as the default tool or not. Defaults to None.
- set_marker_style(marker: Marker) None [source]¶
Configure marker style
- Parameters:
marker – Marker instance
- setup_filter(baseplot: BasePlot) StatefulEventFilter [source]¶
Setup event filter
- Parameters:
baseplot – BasePlot instance
- Returns:
StatefulEventFilter instance
- start(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Start tool action
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- stop(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Stop tool action
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- move(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Move tool action
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- class plotpy.tools.SelectPointsTool(manager, mode='reuse', on_active_item=True, title=None, icon=None, tip=None, end_callback: ~typing.Callable[[~plotpy.tools.curve.SelectPointsTool], ~typing.Any] | None = None, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>, marker_style=None, switch_to_default_tool=None, max_select: int | None = None)[source]¶
Curve points selection tool
- Parameters:
manager – PlotManager Instance
mode – Selection mode. Defaults to “reuse”.
on_active_item – Wether to use the active item or not. Defaults to False.
title – Tool name. Defaults to None.
icon – Tool icon path. Defaults to None.
tip – Available tip. Defaults to None.
end_callback – Callback function taking a Self instance as argument that will
None. (be passed when the user stops dragging the point. Defaults to)
toolbar_id – Toolbar Id to use. Defaults to DefaultToolbarID.
marker_style – Marker style. Defaults to None.
switch_to_default_tool – Wether to use as the default tool or not. Defaults to None.
max_select – Maximum number of points to select. Defaults to None.
- set_marker_style(marker: Marker) None [source]¶
Configure marker style
- Parameters:
marker – Marker instance
- setup_filter(baseplot: BasePlot) StatefulEventFilter [source]¶
Setup event filter
- Parameters:
baseplot – BasePlot instance
- Returns:
StatefulEventFilter instance
- start_single_selection(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Start single selection
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- start_multi_selection(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Start multi selection
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- move(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Move tool action
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- common_stop(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Common stop action
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- stop_single_selection(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Stop single selection
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- stop_multi_selection(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Stop multi selection
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- toggle_marker(marker: Marker) bool [source]¶
Toggle marker
- Parameters:
marker – Marker instance
- Returns:
Wether the marker was added or not
- Return type:
- clear_markers(exclude_detach: tuple[Marker, ...] | None = None) None [source]¶
Clear markers
- Parameters:
exclude_detach – Markers to exclude from detachment. Defaults to None.
- update_labels(filter: StatefulEventFilter) None [source]¶
Update labels
- Parameters:
filter – StatefulEventFilter instance
- class plotpy.tools.EditPointTool(manager: PlotManager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None, end_callback: Callable[[EditPointTool], Any] | None = None)[source]¶
Curve point edition tool
- Parameters:
manager – PlotManager Instance
toolbar_id – Toolbar Id to use . Defaults to DefaultToolbarID.
title – Tool name. Defaults to None.
icon – Tool icon path. Defaults to None.
tip – Available tip. Defaults to None.
switch_to_default_tool – Wether to use as the default tool or not. Defaults to None.
end_callback – Callback function taking a Self instance as argument that will
None. (be passed when the user stops dragging the point. Defaults to)
- set_marker_style(marker: Marker) None [source]¶
Configure marker style
- Parameters:
marker – Marker instance
- setup_filter(baseplot: BasePlot) StatefulEventFilter [source]¶
Setup event filter
- Parameters:
baseplot – BasePlot instance
- Returns:
StatefulEventFilter instance
- undo_curve_modifications(filter: StatefulEventFilter, _event: QEvent | None) None [source]¶
Undo all curve modifications
- Parameters:
filter – StatefulEventFilter instance
_event – Event instance
- insert_point_at_selection(filter: StatefulEventFilter, _event: QEvent | None = None) None [source]¶
Insert point at selection
- Parameters:
filter – StatefulEventFilter instance
_event – Event instance
- start(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Start tool action
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- move_point(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Move point
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
- stop(filter: StatefulEventFilter, event: QMouseEvent) None [source]¶
Stop tool action and save new x and y coordinates.
- Parameters:
filter – StatefulEventFilter instance
event – Qt mouse event
Image tools¶
- class plotpy.tools.ImageStatsTool(manager, setup_shape_cb: Callable[[AbstractShape], None] | None = None, handle_final_shape_cb: Callable[[AbstractShape], None] | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: Any | type[DefaultToolbarID] = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, stats_func: Callable[[BaseImageItem, float, float, float, float]] | None = None, replace: bool = False)[source]¶
Tool to display image statistics in a rectangle
- Parameters:
manager – PlotManager instance
setup_shape_cb – Callback called after shape setup. Defaults to None.
handle_final_shape_cb – Callback called when handling final shape.
None. (Defaults to)
shape_style – tuple of string to set the shape style. Defaults to None.
toolbar_id – toolbar id to use. Defaults to DefaultToolbarID. Defaults to
DefaultToolbarID.
title – tool title. Defaults to None.
icon – tool icon filename. Defaults to None.
tip – user tip to be displayed. Defaults to None.
stats_func – function to get statistics. Defaults to None. (see
get_stats()
for signature and default implementation)replace – True to replace stats (statistics are not added to the base infos but replace them). Defaults to False.
Note
The stats_func function should return a formatted string with statistics on the image rectangular area. The function signature should be:
def stats_func(item, x0, y0, x1, y1): return formatted_string
where item is the image item, x0, y0, x1, y1 are the rectangle coordinates and formatted_string is the formatted string with statistics on the image rectangular area.
Default implementation is the following:
def get_stats( item: BaseImageItem, x0: float, y0: float, x1: float, y1: float, ) -> str: """Return formatted string with stats on image rectangular area (output should be compatible with AnnotatedShape.get_infos) Args: item: image item x0: X0 y0: Y0 x1: X1 y1: Y1 """ ix0, iy0, ix1, iy1 = item.get_closest_index_rect(x0, y0, x1, y1) data = item.data[iy0:iy1, ix0:ix1] p: BaseImageParam = item.param return "<br>".join( [ "%sx%s %s" % (item.data.shape[1], item.data.shape[0], str(item.data.dtype)), "", "%s ≤ x ≤ %s" % (p.xformat % x0, p.xformat % x1), "%s ≤ y ≤ %s" % (p.yformat % y0, p.yformat % y1), "%s ≤ z ≤ %s" % (p.zformat % data.min(), p.zformat % data.max()), "‹z› = " + p.zformat % data.mean(), "σ(z) = " + p.zformat % data.std(), ] )
- set_stats_func(stats_func: Callable[[BaseImageItem, float, float, float, float]], replace: bool = False) None [source]¶
Set the function to get statistics
- Parameters:
stats_func – function to get statistics (see
get_stats()
for signature and default implementation)replace – True to replace stats (statistics are not added to the base infos but replace them). Defaults to False.
- get_last_item() BaseImageItem | None [source]¶
Last image item getter
- Returns:
Returns last image item or None
- create_shape() tuple[ImageStatsRectangle, Literal[0], Literal[2]] [source]¶
Returns a new ImageStatsRectangle instance and the index of handles to display.
- Returns:
New ImageStatsRectangle instance
- setup_shape(shape: ImageStatsRectangle) None [source]¶
Setup and registers given shape.
- Parameters:
shape – Shape to setup
- register_shape(shape: ImageStatsRectangle, final=False) None [source]¶
Register given shape
- Parameters:
shape – Shape to register
final – unused argument. Defaults to False.
- handle_final_shape(shape: ImageStatsRectangle) None [source]¶
Handle final shape
- Parameters:
shape – Shape to handled and register
- get_associated_item(plot: BasePlot) BaseImageItem | None [source]¶
Return a reference to the last image item associated with the tool
- Parameters:
plot – Plot instance
- Returns:
Reference to the last image item associated with the tool
- class plotpy.tools.RotationCenterTool(manager: BasePlot, toolbar_id: Any | type[DefaultToolbarID] = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool=True, rotation_point_move_with_shape=True, rotation_center=True, on_all_items=True)[source]¶
Tool to set the rotation center of an image
- Parameters:
manager – PlotManager instance
toolbar_id – toolbar id to use. Defaults to DefaultToolbarID.. Defaults to DefaultToolbarID.
title – tool title. Defaults to None.
icon – tool icon filename. Defaults to None.
tip – user tip to be displayed. Defaults to None.
switch_to_default_tool – Flag to switch to default tool. Defaults to True.
rotation_point_move_with_shape – Flag to move rotation point with shape when it is moved. Defaults to True.
rotation_center – True if image already has a rotation center, False otherwise.
on_all_items – True if rotation center should be set on all items or False if only on selected ones. Defaults to True.
- setup_filter(baseplot: BasePlot) int [source]¶
Setup event filter and connect signals.
- Parameters:
baseplot – Plot instance
- Returns:
plot’s filter new start state
- update_status(plot: BasePlot) None [source]¶
Updates the tool status depending on the selected items in the given plot.
- Parameters:
plot – Plot instance
- action_triggered(checked: bool) None [source]¶
Action triggered slot
- Parameters:
checked – unused argument
- mouse_press(filter: StatefulEventFilter, event: QEvent) None [source]¶
We create a new shape if it’s the first point otherwise we add a new point.
- Parameters:
filter – StatefulEventFilter instance
event – QEvent instance
- class plotpy.tools.ReverseYAxisTool(manager: PlotManager)[source]¶
Togglable tool to reverse Y axis
- Parameters:
manager – PlotManager Instance
- class plotpy.tools.ZAxisLogTool(manager: PlotManager)[source]¶
Patched tools.ToggleTool
- get_supported_items(plot: BasePlot) list[BaseImageItem] [source]¶
Reimplement tools.ToggleTool method
- class plotpy.tools.AspectRatioTool(manager: PlotManager)[source]¶
Tool to manage the aspect ratio of a plot
- Parameters:
manager – PlotManager instance
Create and return menu for the tool’s action
- activate_command(plot: BasePlot, checked: bool) None [source]¶
Triggers tool action.
- Parameters:
plot – Plot instance
checked – True if tool is checked, False otherwise
- class plotpy.tools.ContrastPanelTool(manager: PlotManager)[source]¶
Tools to adjust contrast using a dataset dialog
- class plotpy.tools.ColormapTool(manager: PlotManager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
Tool used to select and manage colormaps (inculding visualization, edition and saving).
- Parameters:
manager – PlotManager Instance
toolbar_id – Toolbar Id to use. Defaults to DefaultToolbarID.
- activate_command(plot: BasePlot, checked: bool) None [source]¶
Triggers tool action.
- Parameters:
plot – Plot instance
checked – True if tool is checked, False otherwise
- activate_cmap(cmap: str | EditableColormap) None [source]¶
Activate the given colormap. Supports mutliple input types.
- Parameters:
cmap – Cmap to apply for currently selected images.
- class plotpy.tools.ReverseColormapTool(manager: PlotManager)[source]¶
Togglable tool to reverse colormap
- Parameters:
manager – PlotManager Instance
- class plotpy.tools.LockLUTRangeTool(manager: PlotManager)[source]¶
Togglable tool to keep LUT range when updating image data
- Parameters:
manager – PlotManager Instance
- class plotpy.tools.XCSPanelTool(manager: PlotManager)[source]¶
- class plotpy.tools.YCSPanelTool(manager: PlotManager)[source]¶
- class plotpy.tools.CrossSectionTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
-
- create_shape() AnnotatedPoint [source]¶
Create shape for the tool
- setup_shape(shape: AnnotatedPoint) None [source]¶
Set up shape for the tool
- setup_shape_appearance(shape: AnnotatedPoint) None [source]¶
Set up shape appearance
- register_shape(shape: AnnotatedPoint) None [source]¶
Register shape
- handle_final_shape(shape: AnnotatedPoint) None [source]¶
Handle final shape
- class plotpy.tools.AverageCrossSectionTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
- create_shape() AnnotatedRectangle [source]¶
Create shape for the tool
- class plotpy.tools.LineCrossSectionTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
- create_shape() AnnotatedSegment [source]¶
Create shape for the tool
- class plotpy.tools.ImageMaskTool(manager: PlotManager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
Tool to manage image masking
- Parameters:
manager – Plot manager instance
toolbar_id – Toolbar id value
- SIG_APPLIED_MASK_TOOL¶
Signal emitted by ImageMaskTool when mask was applied
Create and return the tool’s action menu for a given manager.
- Parameters:
manager – PlotManager instance
- update_status(plot: BasePlot) None [source]¶
Enables tool if masked_image is set.
- Parameters:
plot – Plot instance
- register_plot(baseplot: BasePlot) None [source]¶
Register plot in the tool instance and connect signals.
- Parameters:
baseplot – Plot instance
- show_mask(state: bool)[source]¶
Shows the image mask depending on given state and if masked_image is set
- Parameters:
state – True to show mask, False otherwise
- show_shapes(state: bool) None [source]¶
Shows the masking shapes depending on given state
- Parameters:
state – True to show shapes, False otherwise
- handle_shape(shape: AbstractShape, inside: bool) None [source]¶
Handles given shape and adds it to the plot and sets it to be the current item
- find_masked_image(plot: BasePlot) MaskedImageItem | MaskedXYImageItem | None [source]¶
Finds the masked image item in the given plot
- Parameters:
plot – Plot instance
- Returns:
MaskedImageItem or MaskedXYImageItem instance if found, None otherwise
- create_shapes_from_masked_areas() None [source]¶
Creates shapes from the masked areas of the masked image (rectangular or ellipse).
- set_masked_image(plot: BasePlot) None [source]¶
Sets the masked image item from the masked image found in the given plot.
- Parameters:
plot – Plot instance
- items_changed(plot: BasePlot) None [source]¶
Updates the masked image and the tool status for a given plot.
- Parameters:
plot – Plot instance
Curve tools¶
- class plotpy.tools.AntiAliasingTool(manager: PlotManager)[source]¶
Anti-aliasing tool
- Parameters:
manager – PlotManager Instance
- class plotpy.tools.DownSamplingTool(manager: PlotManager)[source]¶
Downsample curve tool
- Parameters:
manager – PlotManager Instance
toolbar_id – Toolbar Id to use . Defaults to DefaultToolbarID.
Axes tools¶
- class plotpy.tools.AxisScaleTool(manager)[source]¶
A tool for changing the scale of plot axes.
This tool provides options to switch between linear and logarithmic scales for both x and y axes.
Create and return menu for the tool’s action.
- Parameters:
manager – The plot manager.
- Returns:
A QMenu object containing scale options.
- class plotpy.tools.PlaceAxesTool(manager, setup_shape_cb: ~typing.Callable | None = None, handle_final_shape_cb: ~typing.Callable | None = None, shape_style: tuple[str, str] | None = None, toolbar_id: str = <class 'plotpy.tools.base.DefaultToolbarID'>, title: str | None = None, icon: str | None = None, tip: str | None = None, switch_to_default_tool: bool | None = None)[source]¶
A tool for placing axes on the plot.
This tool allows users to draw a rectangular shape to define the position and size of the axes on the plot.
Miscellaneous tools¶
- class plotpy.tools.SaveAsTool(manager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
- class plotpy.tools.CopyToClipboardTool(manager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
- class plotpy.tools.OpenFileTool(manager, title='Open...', formats='*.*', toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
- class plotpy.tools.OpenImageTool(manager: PlotManager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶
Tool to open an image file
- Parameters:
manager – PlotManager instance
toolbar_id – Toolbar id value. Defaults to DefaultToolbarID.
- class plotpy.tools.SnapshotTool(manager, toolbar_id=<class 'plotpy.tools.base.DefaultToolbarID'>)[source]¶