Reference

High-level features

class plotpy.plot.manager.PlotManager(main: QWidget)[source]

Construct a PlotManager object, a ‘controller’ that organizes relations between plots (BasePlot), panels, tools and toolbars

Parameters:

main (QWidget) – The main parent widget

add_plot(plot: ~plotpy.plot.base.BasePlot, plot_id: ~typing.Any = <class 'plotpy.plot.manager.DefaultPlotID'>) None[source]
Register a plot to the plot manager:
  • plot: BasePlot

  • plot_id (default id is the plot object’s id: id(plot)): unique ID identifying the plot (any Python object), this ID will be asked by the manager to access this plot later.

Plot manager’s registration sequence is the following:
  1. add plots

  2. add panels

  3. add tools

set_default_plot(plot: BasePlot) None[source]

Set default plot

The default plot is the plot on which tools and panels will act.

get_default_plot() BasePlot[source]

Return default plot

The default plot is the plot on which tools and panels will act.

add_panel(panel: PanelWidget) None[source]

Register a panel to the plot manager

Plot manager’s registration sequence is the following:
  1. add plots

  2. add panels

  3. add tools

configure_panels() None[source]

Call all the registred panels ‘configure_panel’ methods to finalize the object construction (this allows to use tools registered to the same plot manager as the panel itself with breaking the registration sequence: “add plots, then panels, then tools”)

add_toolbar(toolbar: QToolBar, toolbar_id: str = 'default') None[source]
Add toolbar to the plot manager

toolbar: a QToolBar object toolbar_id: toolbar’s id (default id is string “default”)

set_default_toolbar(toolbar: QToolBar) None[source]

Set default toolbar

get_default_toolbar() QToolBar[source]

Return default toolbar

add_tool(ToolKlass: type[GuiToolT], *args, **kwargs) GuiToolT[source]
Register a tool to the manager
  • ToolKlass: tool’s class (see Plot tools)

  • args: arguments sent to the tool’s class

  • kwargs: keyword arguments sent to the tool’s class

Plot manager’s registration sequence is the following:
  1. add plots

  2. add panels

  3. add tools

get_tool(ToolKlass: type[GuiToolT]) GuiToolT | None[source]

Return tool instance from its class

Parameters:

ToolKlass – tool’s class (see Plot tools)

Returns:

tool instance

Return type:

GuiTool

add_separator_tool(toolbar_id: str | None = None) None[source]

Register a separator tool to the plot manager: the separator tool is just a tool which insert a separator in the plot context menu

Parameters:

toolbar_id – toolbar’s id (default to None)

set_default_tool(tool: GuiTool) None[source]

Set default tool

Parameters:

tool – tool instance

get_default_tool() GuiTool[source]

Get default tool

Returns:

tool instance

Return type:

GuiTool

activate_default_tool() None[source]

Activate default tool

get_active_tool() GuiTool[source]

Return active tool

Returns:

tool instance

Return type:

GuiTool

set_active_tool(tool: GuiTool | None = None) None[source]

Set active tool (if tool argument is None, the active tool will be the default tool)

Parameters:

tool – tool instance or None

get_plot(plot_id: ~typing.Any = <class 'plotpy.plot.manager.DefaultPlotID'>) BasePlot[source]

Return plot associated to plot_id (if method is called without specifying the plot_id parameter, return the default plot)

Parameters:

plot_id – plot’s id (optional, default to DefaultPlotID)

get_plots() list[BasePlot][source]

Return all registered plots

Returns:

list of plots

Return type:

list[BasePlot]

get_active_plot() BasePlot[source]

Return the active plot

The active plot is the plot whose canvas has the focus otherwise it’s the “default” plot

Returns:

plot instance

Return type:

BasePlot

get_tool_group(groupname: str) QActionGroup[source]

Return the QActionGroup associated to groupname

Parameters:

groupname – group’s name

Returns:

action group

Return type:

QActionGroup

get_main() QWidget[source]

Return the main (parent) widget

Note that for py:class:.plot.PlotWidget objects, this method will return the widget itself because the plot manager is integrated to it.

Returns:

main widget

Return type:

QWidget

set_main(main: QWidget) None[source]

Set the main (parent) widget

Parameters:

main – main widget

get_panel(panel_id: str) PanelWidget[source]

Return panel from its ID Panel IDs are listed in module plotpy.panels

Parameters:

panel_id – panel’s id

Returns:

panel widget

Return type:

PanelWidget

get_itemlist_panel() PlotItemList[source]

Convenience function to get the item list panel

Return None if the item list panel has not been added to this manager

Returns:

item list panel

Return type:

PlotItemList

get_contrast_panel() ContrastAdjustment[source]

Convenience function to get the contrast adjustment panel

Return None if the contrast adjustment panel has not been added to this manager

set_contrast_range(zmin: float, zmax: float) None[source]

Convenience function to set the contrast adjustment panel range

This is strictly equivalent to the following:

# Here, *widget* is for example a PlotWidget instance
# (the same apply for PlotWidget or any
#  class deriving from PlotManager)
widget.get_contrast_panel().set_range(zmin, zmax)
Parameters:
  • zmin – minimum value

  • zmax – maximum value

get_xcs_panel() XCrossSection[source]

Convenience function to get the X-axis cross section panel

Return None if the X-axis cross section panel has not been added to this manager

Returns:

X-axis cross section panel

Return type:

XCrossSection

get_ycs_panel() YCrossSection[source]

Convenience function to get the Y-axis cross section panel

Return None if the Y-axis cross section panel has not been added to this manager

Returns:

Y-axis cross section panel

Return type:

YCrossSection

update_cross_sections() None[source]

Convenience function to update the cross section panels at once

This is strictly equivalent to the following:

# Here, *widget* is for example a PlotWidget instance
# (the same apply for any other class deriving from PlotManager)
widget.get_xcs_panel().update_plot()
widget.get_ycs_panel().update_plot()
get_toolbar(toolbar_id: str = 'default') QToolBar[source]

Return toolbar from its ID

Parameters:

toolbar_id – toolbar’s id (default id is string “default”)

Returns:

toolbar

Return type:

QToolBar

get_context_menu(plot: BasePlot | None = None) QMenu[source]

Return widget context menu – built using active tools

Parameters:

plot – plot instance (default to None)

Returns:

context menu

Return type:

QMenu

update_tools_status(plot: BasePlot | None = None) None[source]

Update tools for current plot

Parameters:

plot – plot instance (default to None)

create_action(title: str, triggered: Callable | None = None, toggled: Callable | None = None, shortcut: QKeySequence | None = None, icon: QIcon | None = None, tip: str | None = None, checkable: bool | None = None, context: ShortcutContext = 1, enabled: bool | None = None)[source]

Create a new QAction

Parameters:
  • parent (QWidget or None) – Parent widget

  • title (str) – Action title

  • triggered (Callable or None) – Triggered callback

  • toggled (Callable or None) – Toggled callback

  • shortcut (QKeySequence or None) – Shortcut

  • icon (QIcon or None) – Icon

  • tip (str or None) – Tooltip

  • checkable (bool or None) – Checkable

  • context (ShortcutContext) – Shortcut context

  • enabled (bool or None) – Enabled

Returns:

New action

Return type:

QAction

register_standard_tools() None[source]

Registering basic tools for standard plot dialog –> top of the context-menu

register_curve_tools() None[source]

Register only curve-related tools

register_image_tools() None[source]

Register only image-related tools

register_other_tools() None[source]

Register other common tools

register_all_curve_tools() None[source]

Register standard, curve-related and other tools

register_all_image_tools() None[source]

Register standard, image-related and other tools

register_all_tools() None[source]

Register standard, curve and image-related and other tools

register_all_annotation_tools() None[source]

Register all annotation tools for the plot

register_curve_annotation_tools() None[source]

Register all curve friendly annotation tools for the plot

register_image_annotation_tools() None[source]

Register all image friendly annotation tools for the plot

synchronize_axis(axis_id: int, plot_ids: list[str]) None[source]

Synchronize axis of plots

Parameters:
  • axis_id – axis id

  • plot_ids – list of plot ids

plot_axis_changed(plot: BasePlot) None[source]

Plot axis changed, update other synchronized plots (if any)

Parameters:

plot – plot instance

class plotpy.plot.PlotOptions(title: str | None = None, xlabel: str | tuple[str, str] | None = None, ylabel: str | tuple[str, str] | None = None, zlabel: str | None = None, xunit: str | tuple[str, str] | None = None, yunit: str | tuple[str, str] | None = None, zunit: str | None = None, yreverse: bool | None = None, aspect_ratio: float = 1.0, lock_aspect_ratio: bool | None = None, curve_antialiasing: bool | None = None, gridparam: GridParam | None = None, section: str = 'plot', type: str | PlotType = 'auto', axes_synchronised: bool = False, force_colorbar_enabled: bool = False, no_image_analysis_widgets: bool = False, show_contrast: bool = False, show_itemlist: bool = False, show_xsection: bool = False, show_ysection: bool = False, xsection_pos: str = 'top', ysection_pos: str = 'right')[source]

Plot options

Parameters:
  • title – The plot title

  • xlabel – (bottom axis title, top axis title) or bottom axis title only

  • ylabel – (left axis title, right axis title) or left axis title only

  • zlabel – The Z-axis label

  • xunit – (bottom axis unit, top axis unit) or bottom axis unit only

  • yunit – (left axis unit, right axis unit) or left axis unit only

  • zunit – The Z-axis unit

  • yreverse – If True, the Y-axis is reversed

  • aspect_ratio – The plot aspect ratio

  • lock_aspect_ratio – If True, the aspect ratio is locked

  • curve_antialiasing – If True, the curve antialiasing is enabled

  • gridparam – The grid parameters

  • section – The plot configuration section name (“plot”, by default)

  • type – The plot type (“auto”, “manual”, “curve” or “image”)

  • axes_synchronised – If True, the axes are synchronised

  • force_colorbar_enabled – If True, the colorbar is always enabled

  • no_image_analysis_widgets – If True, the image analysis widgets are not added

  • show_contrast – If True, the contrast adjustment panel is visible

  • show_itemlist – If True, the itemlist panel is visible

  • show_xsection – If True, the X-axis cross section panel is visible

  • show_ysection – If True, the Y-axis cross section panel is visible

  • xsection_pos – The X-axis cross section panel position (“top” or “bottom”)

  • ysection_pos – The Y-axis cross section panel position (“left” or “right”)

class plotpy.plot.PlotWidget(parent: QWidget | None = None, toolbar: bool = False, options: PlotOptions | None = None, panels: tuple[PanelWidget] | None = None, auto_tools: bool = True)[source]

Plot widget with integrated plot manager, toolbar, tools and panels

Parameters:
  • parent – Parent widget

  • toolbar – Show/hide toolbar

  • options – Plot options

  • panels – Additionnal panels

  • auto_tools – If True, the plot tools are automatically registered. If False, the user must register the tools manually.

get_plot() BasePlot[source]

Return the plot object

Returns:

The plot object

Return type:

BasePlot

get_toolbar() QToolBar[source]

Return main toolbar

Returns:

The plot widget main toolbar

get_manager() PlotManager[source]

Return the plot manager

Returns:

The plot widget manager

configure_manager(panels: tuple[PanelWidget] | None = None, toolbar: bool = True) None[source]

Configure the plot manager

Parameters:
  • panels – additionnal panels (list, tuple). Defaults to None.

  • toolbar – [description]. Defaults to True.

class plotpy.plot.PlotDialog(parent: QWidget | None = None, toolbar: bool = False, options: PlotOptions | None = None, panels: list[PanelWidget] | None = None, auto_tools: bool = True, title: str = 'PlotPy', icon: str = 'plotpy.svg', edit: bool = False)[source]

Plotting dialog box with integrated plot manager

Parameters:
  • parent – parent widget

  • toolbar – show/hide toolbar

  • options – plot options

  • panels – additionnal panels

  • auto_tools – If True, the plot tools are automatically registered. If False, the user must register the tools manually.

  • title – The window title

  • icon – The window icon

  • edit – If True, the plot is editable

get_plot() BasePlot | None[source]

Return the plot object

Returns:

The plot object

Return type:

BasePlot

get_toolbar() QToolBar[source]

Return main toolbar

Returns:

The plot widget main toolbar

get_manager() PlotManager[source]

Return the plot manager

Returns:

The plot widget manager

setup_widget(toolbar: bool = False, options: PlotOptions | None = None, panels: list[PanelWidget] | None = None, auto_tools: bool = False) None[source]

Setup the widget

Parameters:
  • toolbar – If True, the plot toolbar is displayed

  • options – Plot options

  • panels – The panels to add to the plot

  • auto_tools – If True, the plot tools are automatically registered. If False, the user must register the tools manually.

add_widget(widget: QWidget, row: int | None = None, column: int | None = None, rowspan: int | None = None, columnspan: int | None = None) None[source]

Add widget to the widget main layout

Parameters:
  • widget – The widget to add

  • row – The row index

  • column – The column index

  • rowspan – The row span

  • columnspan – The column span

populate_plot_layout() None[source]

Populate the plot layout

setup_layout() None[source]

Setup the widget layout

install_button_layout() None[source]

Install standard buttons (OK, Cancel) in dialog button box layout

This method may be overriden to customize the button box

register_tools()[source]

Register the plotting tools: the base implementation of this method register tools according to the plot type (curve, image, etc.)

This method may be overriden to provide a fully customized set of tools

register_annotation_tools()[source]

Register the annotation tools: the base implementation of this method register tools according to the plot type (curve, image, etc.)

This method may be overriden to provide a fully customized set of tools

class plotpy.plot.PlotWindow(parent: QWidget | None = None, toolbar: bool = False, options: PlotOptions | None = None, panels: list[PanelWidget] | None = None, auto_tools: bool = True, title: str = 'PlotPy', icon: str = 'plotpy.svg')[source]

Plotting window with integrated plot manager

Parameters:
  • parent – parent widget

  • toolbar – show/hide toolbar

  • options – plot options

  • panels – additionnal panels

  • auto_tools – If True, the plot tools are automatically registered. If False, the user must register the tools manually.

  • title – The window title

  • icon – The window icon

get_plot() BasePlot | None[source]

Return the plot object

Returns:

The plot object

Return type:

BasePlot

get_toolbar() QToolBar[source]

Return main toolbar

Returns:

The plot widget main toolbar

get_manager() PlotManager[source]

Return the plot manager

Returns:

The plot widget manager

setup_widget(toolbar: bool = False, options: PlotOptions | None = None, panels: list[PanelWidget] | None = None, auto_tools: bool = False) None[source]

Setup the widget

Parameters:
  • toolbar – If True, the plot toolbar is displayed

  • options – Plot options

  • panels – The panels to add to the plot

  • auto_tools – If True, the plot tools are automatically registered. If False, the user must register the tools manually.

add_widget(widget: QWidget, row: int | None = None, column: int | None = None, rowspan: int | None = None, columnspan: int | None = None) None[source]

Add widget to the widget main layout

Parameters:
  • widget – The widget to add

  • row – The row index

  • column – The column index

  • rowspan – The row span

  • columnspan – The column span

populate_plot_layout() None[source]

Populate the plot layout

setup_layout() None[source]

Setup the widget layout

register_tools()[source]

Register the plotting tools: the base implementation of this method register tools according to the plot type (curve, image, etc.)

This method may be overriden to provide a fully customized set of tools

register_annotation_tools()[source]

Register the annotation tools: the base implementation of this method register tools according to the plot type (curve, image, etc.)

This method may be overriden to provide a fully customized set of tools

closeEvent(event) None[source]

Reimplement the close event to close all panels

Parameters:

event – The close event

class plotpy.plot.SyncPlotWindow(parent: QWidget | None = None, toolbar: bool = True, options: PlotOptions | None = None, auto_tools: bool = True, title: str = 'PlotPy', icon: str = 'plotpy.svg')[source]

Window for showing plots, optionally synchronized

Parameters:
  • parent – parent widget

  • toolbar – show/hide toolbar

  • options – plot options

  • panels – additionnal panels

  • auto_tools – If True, the plot tools are automatically registered. If False, the user must register the tools manually.

  • title – The window title

  • icon – The window icon

Usage: first, create a window, then add plots to it, then call the SyncPlotWindow.finalize_configuration() method to add panels and eventually register tools.

Example:

from plotpy.plot import BasePlot, SyncPlotWindow
win = SyncPlotWindow(title="My window")
plot = BasePlot()
win.add_plot(plot)
win.finalize_configuration()
win.show()
get_toolbar() QToolBar[source]

Return main toolbar

Returns:

The plot widget main toolbar

get_manager() PlotManager[source]

Return the plot manager

Returns:

The plot widget manager

finalize_configuration() None[source]

Configure plot manager and register all tools

rescale_plots() None[source]

Rescale all plots

showEvent(event)[source]

Reimplement Qt method

add_plot(row: int, col: int, plot: BasePlot, sync: bool = False, plot_id: str | None = None) None[source]

Add plot to window

Parameters:
  • row – The row index

  • col – The column index

  • plot – The plot to add

  • sync – If True, the axes are synchronized

  • plot_id – The plot id

get_plots() list[BasePlot][source]

Return the plots

Returns:

The plots

Return type:

list[BasePlot]

Low-level features

class plotpy.constants.PlotType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

This is the enum used for the plot type. Defines how the plot should deal with the different PlotItems types (curves and images)

AUTO = 1

Automatic plot type. The first PlotItem attached to the plot sets the type. All tools (curve and image related) are registered and accessible depending on the last selected PlotItem.

CURVE = 2

Curve specialized plot. The y axis is not reversed and the aspect ratio is not locked by default. Only CURVE typed tools are automatically registered.

IMAGE = 3

Image specialized plot. The y axis is reversed and the aspect ratio is locked by default. Only IMAGE typed tools are automatically registered.

MANUAL = 4

No assumption is made on the type of items to be displayed on the plot. Acts like the CURVE value of the enum for y axis and aspect ratio. No tool are automatically registered.

class plotpy.plot.BasePlot(parent: QWidget | None = None, options: BasePlotOptions | None = None)[source]

Enhanced QwtPlot class providing methods for handling items and axes better

It distinguishes activatable items from basic QwtPlotItems.

Activatable items must support IBasePlotItem interface and should be added to the plot using add_item methods.

Parameters:
  • parent – parent widget

  • options – plot options

SIG_ITEM_MOVED(PyQt_PyObject, double, double, double, double)

Signal emitted by plot when an IBasePlotItem object was moved

Parameters:
  • item – the moved item

  • x0 (float) – the old x position

  • y0 (float) – the old y position

  • x1 (float) – the new x position

  • y1 (float) – the new y position

SIG_ITEM_HANDLE_MOVED(PyQt_PyObject)

Signal emitted by plot when an IBasePlotItem handle was moved

Parameters:

item – the moved item

SIG_ITEM_RESIZED(PyQt_PyObject, double, double)

Signal emitted by plot when an IBasePlotItem object was resized

Parameters:
  • item – the resized item

  • zoom_dx (float) – the zoom factor along the x axis

  • zoom_dy (float) – the zoom factor along the y axis

SIG_ITEM_ROTATED(PyQt_PyObject, double)

Signal emitted by plot when an IBasePlotItem object was rotated

Parameters:
  • item – the rotated item

  • angle (float) – the new angle (in radians)

SIG_MARKER_CHANGED(PyQt_PyObject)

Signal emitted by plot when a shape.Marker position changes

Parameters:

marker – the moved marker

SIG_AXES_CHANGED(PyQt_PyObject)

Signal emitted by plot when a shape.Axes position (or the angle) changes

Parameters:

axes – the moved axes

SIG_ANNOTATION_CHANGED(PyQt_PyObject)

Signal emitted by plot when an annotation.AnnotatedShape position changes

Parameters:

annotation – the moved annotation

SIG_RANGE_CHANGED(PyQt_PyObject, double, double)

Signal emitted by plot when the a shape.XRangeSelection range changes

Parameters:
  • selection – the selection item

  • xmin (float) – the new minimum x value

  • xmax (float) – the new maximum x value

SIG_ITEMS_CHANGED(PyQt_PyObject)

Signal emitted by plot when item list has changed (item removed, added, …)

Parameters:

plot – the plot

SIG_ITEM_PARAMETERS_CHANGED(PyQt_PyObject)

Signal emitted by plot when item parameters have changed (through the item’s parameters dialog, or when setting colormap using the dedicated tool)

Parameters:

item – the item

SIG_ACTIVE_ITEM_CHANGED(PyQt_PyObject)

Signal emitted by plot when selected item has changed

Parameters:

plot – the plot

SIG_ITEM_REMOVED(PyQt_PyObject)

Signal emitted by plot when an item was deleted from the item list or using the delete item tool

Parameters:

item – the deleted item

SIG_ITEM_SELECTION_CHANGED(PyQt_PyObject)

Signal emitted by plot when an item is selected

Parameters:

item – the selected item

SIG_PLOT_LABELS_CHANGED(PyQt_PyObject)

Signal emitted by plot when plot’s title or any axis label has changed

Parameters:

plot – the plot

SIG_AXIS_DIRECTION_CHANGED(PyQt_PyObject, PyQt_PyObject)

Signal emitted by plot when any plot axis direction has changed

Parameters:
  • plot – the plot

  • axis_id – the axis id (“left”, “right”, “bottom”, “top”)

SIG_LUT_CHANGED(PyQt_PyObject)

Signal emitted by plot when LUT has been changed by the user

Parameters:

plot – the plot

SIG_MASK_CHANGED(PyQt_PyObject)

Signal emitted by plot when image mask has changed

Parameters:

plot – the plot

SIG_CS_CURVE_CHANGED(PyQt_PyObject)

Signal emitted by cross section plot when cross section curve data has changed

Parameters:

plot – the plot

SIG_PLOT_AXIS_CHANGED(PyQt_PyObject)

Signal emitted by plot when plot axis has changed, e.g. when panning/zooming

Parameters:

plot – the plot

on_active_curve(x: float, y: float) tuple[float, float][source]

Callback called when the active curve is moved

Parameters:
  • x (float) – the x position

  • y (float) – the y position

get_coordinates_str(x: float, y: float) str[source]

Return the coordinates string

Parameters:
  • x (float) – the x position

  • y (float) – the y position

Returns:

the coordinates string

Return type:

str

set_marker_axes() None[source]

Set the axes of the markers

do_move_marker(event: QMouseEvent) None[source]

Move the marker

Parameters:

event (QMouseEvent) – the event

do_pan_view(dx: tuple[float, float, float, float], dy: tuple[float, float, float, float], replot: bool = True) None[source]

Translate the active axes according to dx, dy axis ‘state’ tuples

Parameters:
do_zoom_view(dx: tuple[float, float, float, float], dy: tuple[float, float, float, float], lock_aspect_ratio: bool | None = None, replot: bool = True) None[source]

Change the scale of the active axes (zoom/dezoom) according to dx, dy axis ‘state’ tuples

We try to keep initial pos fixed on the canvas as the scale changes

Parameters:
  • dx (tuple[float, float, float, float]) – the x axis ‘state’ tuple

  • dy (tuple[float, float, float, float]) – the y axis ‘state’ tuple

  • lock_aspect_ratio – if True, the aspect ratio is locked

  • replot – if True, do a full replot else just update the axes to avoid a redraw (default: True)

do_zoom_rect_view(start: QPointF, end: QPointF) None[source]

Zoom to rectangle defined by start and end points

Parameters:
get_default_item() IBasePlotItem | None[source]

Return default item, depending on plot’s default item type (e.g. for a curve plot, this is a curve item type).

Return nothing if there is more than one item matching the default item type.

Returns:

the default item

Return type:

IBasePlotItem

mouseDoubleClickEvent(event: QMouseEvent) None[source]

Reimplement QWidget method

showEvent(event) None[source]

Reimplement Qwt method

resizeEvent(event)[source]

Reimplement Qt method to resize widget

set_manager(manager: PlotManager, plot_id: int) None[source]

Set the associated plot.manager.PlotManager instance

Parameters:
sizeHint() QSize[source]

Preferred size

get_title() str[source]

Get plot title

set_title(title: str) None[source]

Set plot title

Parameters:

title (str) – the title

get_axis_id(axis_name: str | int) int[source]

Return axis ID from axis name If axis ID is passed directly, check the ID

Parameters:

axis_name (str | int) – the axis name or ID

Returns:

the axis ID

Return type:

int

read_axes_styles(section: str, options: list[str, str, str, str]) None[source]

Read axes styles from section and options (one option for each axis in the order left, right, bottom, top)

Skip axis if option is None

Parameters:
get_axis_title(axis_id: int) str[source]

Get axis title

Parameters:

axis_id (int) – the axis id

Returns:

the axis title

Return type:

str

set_axis_title(axis_id: int, text: str) None[source]

Set axis title

Parameters:
  • axis_id (int) – the axis id

  • text (str) – the axis title

get_axis_unit(axis_id: int) str[source]

Get axis unit

Parameters:

axis_id (int) – the axis id

Returns:

the axis unit

Return type:

str

set_axis_unit(axis_id: int, text: str) None[source]

Set axis unit

Parameters:
  • axis_id (int) – the axis id

  • text (str) – the axis unit

get_axis_font(axis_id: int) QFont[source]

Get axis font

Parameters:

axis_id (int) – the axis id

Returns:

the axis font

Return type:

QFont

set_axis_font(axis_id: int, font: QFont) None[source]

Set axis font

Parameters:
  • axis_id (int) – the axis id

  • font (QFont) – the axis font

get_axis_color(axis_id: int) str[source]

Get axis color (color name, i.e. string)

Parameters:

axis_id (int) – the axis id

Returns:

the axis color

Return type:

str

set_axis_color(axis_id: int, color: str | QColor) None[source]

Set axis color

Parameters:
  • axis_id (int) – the axis id

  • color (str | QColor) – the axis color

update_axis_style(axis_id: int) None[source]

Update axis style

Parameters:

axis_id (int) – the axis id

update_all_axes_styles() None[source]

Update all axes styles

get_axis_limits(axis_id: int) tuple[float, float][source]

Return axis limits (minimum and maximum values)

Parameters:

axis_id (int) – the axis id

Returns:

the axis limits

Return type:

tuple[float, float]

set_axis_limits(axis_id: int, vmin: float, vmax: float, stepsize: int = 0) None[source]

Set axis limits (minimum and maximum values) and step size

Parameters:
  • axis_id (int) – the axis id

  • vmin (float) – the minimum value

  • vmax (float) – the maximum value

  • stepsize (int) – the step size (optional, default=0)

set_axis_ticks(axis_id: int, nmajor: int | None = None, nminor: int | None = None) None[source]

Set axis maximum number of major ticks and maximum of minor ticks

Parameters:
  • axis_id (int) – the axis id

  • nmajor (int) – the maximum number of major ticks

  • nminor (int) – the maximum number of minor ticks

get_axis_scale(axis_id: int) str[source]

Return the name (‘lin’ or ‘log’) of the scale used by axis

Parameters:

axis_id (int) – the axis id

Returns:

the axis scale

Return type:

str

set_axis_scale(axis_id: int, scale: str, autoscale: bool = True) None[source]

Set axis scale

Parameters:
  • axis_id (int) – the axis id

  • scale (str) – the axis scale (‘lin’ or ‘log’)

  • autoscale (bool) – autoscale the axis (optional, default=True)

Example

self.set_axis_scale(curve.yAxis(), ‘lin’)

get_scales() tuple[str, str][source]

Return active curve scales

Example

self.get_scales() -> (‘lin’, ‘lin’)

set_scales(xscale: str, yscale: str) None[source]

Set active curve scales

Parameters:
  • xscale (str) – the x axis scale (‘lin’ or ‘log’)

  • yscale (str) – the y axis scale (‘lin’ or ‘log’)

Example

self.set_scales(‘lin’, ‘lin’)

enable_used_axes()[source]

Enable only used axes For now, this is needed only by the pyplot interface

disable_unused_axes()[source]

Disable unused axes

get_items(z_sorted: bool = False, item_type: type[IItemType | IBasePlotItem] | None = None) list[IBasePlotItem][source]

Return widget’s item list (items are based on IBasePlotItem’s interface)

Parameters:
  • z_sorted (bool) – sort items by z order (optional, default=False)

  • item_type (IItemType) – the item type (optional, default=None)

Returns:

the item list

Return type:

list[IBasePlotItem]

get_public_items(z_sorted: bool = False, item_type: IBasePlotItem | None = None) list[IBasePlotItem][source]

Return widget’s public item list (items are based on IBasePlotItem’s interface)

Parameters:
  • z_sorted (bool) – sort items by z order (optional, default=False)

  • item_type (IItemType) – the item type (optional, default=None)

Returns:

the item list

Return type:

list[IBasePlotItem]

get_private_items(z_sorted: bool = False, item_type: IBasePlotItem | None = None) list[IBasePlotItem][source]

Return widget’s private item list (items are based on IBasePlotItem’s interface)

Parameters:
  • z_sorted (bool) – sort items by z order (optional, default=False)

  • item_type (IItemType) – the item type (optional, default=None)

Returns:

the item list

Return type:

list[IBasePlotItem]

copy_to_clipboard() None[source]

Copy widget’s window to clipboard

save_widget(fname: str) None[source]

Grab widget’s window and save it to filename (/.png, /.pdf)

Parameters:

fname (str) – the filename

get_selected_items(z_sorted=False, item_type: IBasePlotItem | None = None) list[IBasePlotItem][source]

Return selected items

Parameters:
  • z_sorted (bool) – sort items by z order (optional, default=False)

  • item_type (IItemType) – the item type (optional, default=None)

Returns:

the selected items

Return type:

list[IBasePlotItem]

get_max_z() int[source]

Return maximum z-order for all items registered in plot If there is no item, return 0

Returns:

the maximum z-order

Return type:

int

add_item(item: IBasePlotItem, z: int | None = None, autoscale: bool = True) None[source]

Add a plot item instance to this plot widget

Parameters:
  • item (IBasePlotItem) – the item

  • z (int) – the z order (optional, default=None)

  • autoscale (bool) – autoscale the plot (optional, default=True)

add_item_with_z_offset(item: IBasePlotItem, zoffset: int) None[source]

Add a plot item instance within a specified z range, over an offset

Parameters:
del_items(items: list[IBasePlotItem]) None[source]

Remove item from widget

Parameters:

items (list[IBasePlotItem]) – the items

del_item(item: IBasePlotItem) None[source]

Remove item from widget Convenience function (see ‘del_items’)

Parameters:

item (IBasePlotItem) – the item

set_item_visible(item: IBasePlotItem, state: bool, notify: bool = True, replot: bool = True) None[source]

Show/hide item and emit a SIG_ITEMS_CHANGED signal

Parameters:
  • item (IBasePlotItem) – the item

  • state (bool) – the visibility state

  • notify (bool) – notify the item list (optional, default=True)

  • replot (bool) – replot the widget (optional, default=True)

show_items(items: list[IBasePlotItem] | None = None, item_type: IBasePlotItem | None = None) None[source]

Show items (if items is None, show all items)

Parameters:
hide_items(items: list[IBasePlotItem] | None = None, item_type: IBasePlotItem | None = None) None[source]

Hide items (if items is None, hide all items)

Parameters:
save_items(iofile: str | IO[str], selected: bool = False) None[source]

Save (serializable) items to file using the pickle protocol

Parameters:
  • iofile (str | IO[str]) – the file object or filename

  • selected (bool) – if True, will save only selected items (optional, default=False)

See also BasePlot.restore_items()

restore_items(iofile: str | IO[str]) None[source]

Restore items from file using the pickle protocol

Parameters:

iofile (str | IO[str]) – the file object or filename

See also BasePlot.save_items()

serialize(writer: guidata.io.HDF5Writer | guidata.io.INIWriter | guidata.io.JSONWriter) None[source]

Serialize object to HDF5 writer

Parameters:

writer – HDF5, INI or JSON writer

See also BasePlot.restore_items()

deserialize(reader: guidata.io.HDF5Reader | guidata.io.INIReader | guidata.io.JSONReader) None[source]

Deserialize object from HDF5 reader

Parameters:

reader – HDF5, INI or JSON reader

See also BasePlot.save_items()

set_items(*args: IBasePlotItem) None[source]

Utility function used to quickly setup a plot with a set of items

Parameters:

args – the items

Example

self.set_items(item1, item2, item3)

del_all_items(except_grid: bool = True) None[source]

Del all items, eventually (default) except grid

Parameters:

except_grid (bool) – if True, don’t delete grid (optional, default=True)

move_up(item_list: list[IBasePlotItem] | IBasePlotItem) bool[source]

Move item(s) up, i.e. to the foreground (swap item with the next item in z-order)

Parameters:

item_list (list[IBasePlotItem] | IBasePlotItem) – the item(s)

Returns:

True if items have been moved effectively

Return type:

bool

move_down(item_list: list[IBasePlotItem] | IBasePlotItem) bool[source]

Move item(s) down, i.e. to the background (swap item with the previous item in z-order)

Parameters:

item_list (list[IBasePlotItem] | IBasePlotItem) – the item(s)

Returns:

True if items have been moved effectively

Return type:

bool

set_items_readonly(state: bool) None[source]

Set all items readonly state to state Default item’s readonly state: False (items may be deleted)

Parameters:

state (bool) – the readonly state

select_item(item: IBasePlotItem) None[source]

Select item

Parameters:

item (IBasePlotItem) – the item

unselect_item(item: IBasePlotItem) None[source]

Unselect item

Parameters:

item (IBasePlotItem) – the item

get_last_active_item(item_type: type[IItemType]) IBasePlotItem | None[source]

Return last active item corresponding to passed item_type

Parameters:

item_type (IItemType) – the item type

Returns:

the item

Return type:

IBasePlotItem

select_all() None[source]

Select all selectable items

unselect_all() None[source]

Unselect all selected items

select_some_items(items: list[IBasePlotItem]) None[source]

Select items

Parameters:

items (list[IBasePlotItem]) – the items

set_active_item(item: IBasePlotItem) None[source]

Set active item, and unselect the old active item. For CurveItems, the grid axes are changed according to the selected item

Parameters:

item (IBasePlotItem) – the item

get_active_axes() tuple[int, int][source]

Return active axes

Returns:

the active axes IDs

Return type:

tuple[int, int]

get_active_item(force: bool = False) IBasePlotItem | None[source]

Return active item Force item activation if there is no active item

Parameters:

force (bool) – force item activation (optional, default=False)

Returns:

the active item or None

Return type:

IBasePlotItem

get_nearest_object(pos: QPointF, close_dist: int = 0) tuple[IBasePlotItem | None, float, int | None, bool][source]

Return nearest item from position ‘pos’

Parameters:
  • pos (QPointF) – the position

  • close_dist (int) – the distance (optional, default=0)

Returns:

the nearest item

Return type:

tuple[IBasePlotItem | None, float, int | None, bool]

If close_dist > 0:

Return the first found item (higher z) which distance to ‘pos’ is less than close_dist

else:

Return the closest item

get_nearest_object_in_z(pos: QPointF) tuple[IBasePlotItem | None, int, bool | None, int | None][source]

Return nearest item for which position ‘pos’ is inside of it (iterate over items with respect to their ‘z’ coordinate)

Parameters:

pos (QPointF) – the position

Returns:

the nearest item

Return type:

tuple[IBasePlotItem | None, int, bool | None, int | None]

get_context_menu() QMenu[source]

Return widget context menu

Returns:

the context menu

Return type:

QMenu

get_plot_parameters_status(key: str) bool[source]

Return True if the plot parameters are available

Parameters:

key (str) – the parameter key

Returns:

True if the plot parameters are available

Return type:

bool

get_selected_item_parameters(itemparams: ItemParameters) None[source]

Return a list of DataSets for selected items parameters the datasets will be edited and passed back to set_plot_parameters

Parameters:

itemparams (ItemParameters) – the item parameters

get_axesparam_class(item: IBasePlotItem) AxesParam[source]

Return AxesParam dataset class associated to item’s type

Parameters:

item (IBasePlotItem) – the item

Returns:

the AxesParam dataset class

Return type:

AxesParam

get_plot_parameters(key: str, itemparams: ItemParameters) None[source]

Return a list of DataSets for a given parameter key the datasets will be edited and passed back to set_plot_parameters

this is a generic interface to help building context menus using the BasePlotMenuTool

Parameters:
  • key (str) – the parameter key

  • itemparams (ItemParameters) – the item parameters

set_item_parameters(itemparams: ItemParameters) None[source]

Set item (plot, here) parameters

Parameters:

itemparams (ItemParameters) – the item parameters

edit_plot_parameters(key: str) None[source]

Edit plot parameters

Parameters:

key (str) – the parameter key

edit_axis_parameters(axis_id: int) None[source]

Edit axis parameters

Parameters:

axis_id (int) – the axis ID

add_autoscale_types(item_types: tuple[type]) None[source]

Add item types to autoscale list

Parameters:

item_types (tuple[type]) – the item types

add_autoscale_excludes(items: list[IBasePlotItem]) None[source]

Add items to autoscale excludes list

Parameters:

items (list[IBasePlotItem]) – the items

remove_autoscale_excludes(items: list[IBasePlotItem]) None[source]

Remove items from autoscale excludes list

Parameters:

items (list[IBasePlotItem]) – the items

get_auto_scale_excludes() list[IBasePlotItem][source]

Return autoscale excludes

Returns:

the items

Return type:

list[IBasePlotItem]

do_autoscale(replot: bool = True, axis_id: int | None = None) None[source]

Do autoscale on all axes

Parameters:
  • replot (bool) – replot the widget (optional, default=True)

  • axis_id (int | None) – the axis ID (optional, default=None)

disable_autoscale() None[source]

Re-apply the axis scales so as to disable autoscaling without changing the view

invalidate() None[source]

Invalidate paint cache and schedule redraw use instead of replot when only the content of the canvas needs redrawing (axes, shouldn’t change)

get_axis_direction(axis_id: int | str) bool[source]

Return axis direction of increasing values

Parameters:

axis_id (int | str) – axis id (BasePlot.Y_LEFT, BasePlot.X_BOTTOM, …) or string: ‘bottom’, ‘left’, ‘top’ or ‘right’

Returns:

False (default)

Return type:

bool

set_axis_direction(axis_id: int | str, reverse: bool = False) None[source]

Set axis direction of increasing values

Parameters:
  • axis_id (int | str) – axis id (BasePlot.Y_LEFT, BasePlot.X_BOTTOM, …) or string: ‘bottom’, ‘left’, ‘top’ or ‘right’

  • reverse (bool) – False (default)

If reverse is False:

  • x-axis values increase from left to right

  • y-axis values increase from bottom to top

If reverse is True:

  • x-axis values increase from right to left

  • y-axis values increase from top to bottom

set_titles(title: str | None = None, xlabel: str | tuple[str, str] | None = None, ylabel: str | tuple[str, str] | None = None, xunit: str | tuple[str, str] | None = None, yunit: str | tuple[str, str] | None = None) None[source]

Set plot and axes titles at once

Parameters:
  • title (str) – plot title

  • xlabel (str | tuple[str, str]) – (bottom axis title, top axis title) or bottom axis title only

  • ylabel (str | tuple[str, str]) – (left axis title, right axis title) or left axis title only

  • xunit (str | tuple[str, str]) – (bottom axis unit, top axis unit) or bottom axis unit only

  • yunit (str | tuple[str, str]) – (left axis unit, right axis unit) or left axis unit only

set_pointer(pointer_type: str | None) None[source]

Set pointer.

Parameters:

pointer_type (str) – pointer type (None, ‘canvas’, ‘curve’)

Meaning of pointer_type:

  • None: disable pointer

  • ‘canvas’: enable canvas pointer

  • ‘curve’: enable on-curve pointer

set_antialiasing(checked: bool) None[source]

Toggle curve antialiasing

Parameters:

checked (bool) – True to enable antialiasing

set_plot_limits(x0: float, x1: float, y0: float, y1: float, xaxis: str | int = 'bottom', yaxis: str | int = 'left') None[source]

Set plot scale limits

Parameters:
  • x0 (float) – x min

  • x1 (float) – x max

  • y0 (float) – y min

  • y1 (float) – y max

  • xaxis (str | int) – x axis name or id (optional, default=’bottom’)

  • yaxis (str | int) – y axis name or id (optional, default=’left’)

get_plot_limits(xaxis: str | int = 'bottom', yaxis: str | int = 'left') tuple[float, float, float, float][source]

Return plot scale limits

Parameters:
  • xaxis (str | int) – x axis name or id (optional, default=’bottom’)

  • yaxis (str | int) – y axis name or id (optional, default=’left’)

Returns:

x0, x1, y0, y1

Return type:

tuple[float, float, float, float]

get_current_aspect_ratio() float | None[source]

Return current aspect ratio

Returns:

The current aspect ratio or None if the aspect ratio cannot be computed (this happens when the plot has been shrunk to a size so that the width is zero)

get_aspect_ratio() float[source]

Return aspect ratio

Returns:

the aspect ratio

Return type:

float

set_aspect_ratio(ratio: float | None = None, lock: bool | None = None) None[source]

Set aspect ratio

Parameters:
  • ratio (float) – the aspect ratio (optional, default=None)

  • lock (bool) – lock aspect ratio (optional, default=None)

apply_aspect_ratio(full_scale: bool = False) None[source]

Apply aspect ratio

Parameters:

full_scale – if True, the aspect ratio is applied to the full scale (this argument is True only when doing autoscale, i.e. in method do_autoscale(): it is necessary to ensure that the whole image items are visible after autoscale, whatever their aspect ratio)

notify_colormap_changed() None[source]

Levels histogram range has changed

update_colormap_axis(item: IColormapImageItemType) None[source]

Update colormap axis

Parameters:

item (IColormapImageItemType) – the item

classmethod register_autoscale_type(type_)[source]

Add type_ to the list of types used to check if an item is taken into account to compute the scale.

Class must defines the following methods:

  • is_empty(): returns True if the item is empty

  • boundingRect(): returns the bouding rect as a QRectF

  • isVisible(): returns True if item is visible

  • xAxis() and yAxis()

class plotpy.plot.BasePlotOptions(title: str | None = None, xlabel: str | tuple[str, str] | None = None, ylabel: str | tuple[str, str] | None = None, zlabel: str | None = None, xunit: str | tuple[str, str] | None = None, yunit: str | tuple[str, str] | None = None, zunit: str | None = None, yreverse: bool | None = None, aspect_ratio: float = 1.0, lock_aspect_ratio: bool | None = None, curve_antialiasing: bool | None = None, gridparam: GridParam | None = None, section: str = 'plot', type: str | PlotType = 'auto', axes_synchronised: bool = False, force_colorbar_enabled: bool = False)[source]

Base plot options

Parameters:
  • title – The plot title

  • xlabel – (bottom axis title, top axis title) or bottom axis title only

  • ylabel – (left axis title, right axis title) or left axis title only

  • zlabel – The Z-axis label

  • xunit – (bottom axis unit, top axis unit) or bottom axis unit only

  • yunit – (left axis unit, right axis unit) or left axis unit only

  • zunit – The Z-axis unit

  • yreverse – If True, the Y-axis is reversed

  • aspect_ratio – The plot aspect ratio

  • lock_aspect_ratio – If True, the aspect ratio is locked

  • curve_antialiasing – If True, the curve antialiasing is enabled

  • gridparam – The grid parameters

  • section – The plot configuration section name (“plot”, by default)

  • type – The plot type (“auto”, “manual”, “curve” or “image”)

  • axes_synchronised – If True, the axes are synchronised

  • force_colorbar_enabled – If True, the colorbar is always enabled

copy(other_options: dict[str, Any]) BasePlotOptions[source]

Copy the options and replace some of them with the given dictionary

Parameters:

other_options – The dictionary

Returns:

The new options

Return type:

BasePlotOptions