7.1. pyopus.plotter.plotwidget — PyQt5 canvas for displaying Matplotlib plots

Inheritance diagram of pyopus.plotter.plotwidget

PyQt canvas for displaying Matplotlib plots

This module provides a PyQt canvas for Matplotlib to render its plots on. The canvas supports zooming and displays cursor position in axes coordinates as the cursor moves across the canvas.

A plot window is an object of the QWidget class. The canvas itself is an object of the PlotPanel class.

The module also provides saving of the plots to raster (e.g. PNG) or vector files (e.g. Postscript).

class pyopus.plotter.plotwidget.QPFigureCanvas(parent=None, lock=None, showCrosshair=True, showRubberband=True, pointEvents=True, selectionEvents=True, zooming=True, figpx=None, figsize=None, dpi=None)[source]

A Matplotlib canvas suitable for embedding in PyQt5 applications.

For parent see PyQt documentation.

lock is a threading.Lock object for preventing other threads from accessing gui data while the gui thread uses them.

Setting showCrosshair and showRubberband to True enables the corresponding facilities of the canvas.

By setting point and selection to True the canvas emits PointEvent (SelectionEvent) events whenever crosshair position (rubberband) is changed.

Setting zooming to True enables zooming.

figsize is a tuple specifying the figure width and height in inches. Together with dpi they define the size of the figure in pixels.

figpx is a tuple with the horizontal and vertical size of the figure in pixels. If it is given it overrides the figsize setting. dpi is used for obtaining the figure size in inches.

If neither figsize nor figpx are given the settings from matplotlibrc are used. The same holds for dpi.

Holding down the left button and moving the mouse selects the area to be zoomed. The zooming is performed when the button is released.

Right-clicking zooms out to the previous view.

Pressing the I key identifies the nearest curve and shows a tooltip.

emitCoordinates(event)[source]

Extracts coordinate information and emits a newCoordinates signal.

enableCoordinatesEvents(state)[source]

Enable or disable emitting newCoordinates signal.

enablePicking(axes, width=8)[source]

Enables picking for all artists under given axes.

enableSelectionEvents(state)[source]

Enable or disable newSelection signal.

enableZooming(state)[source]

Enable or disable zooming in/out when the user makes an area selection or right-clicks the axes.

event(self, a0: QEvent) bool[source]
getFigure()[source]

Returns the MatPlotLib Figure associated with this canvas.

newCoordinates

Signal that gets emitted every time rubberband is changed

on_button_press_event(event)[source]

A handler for matplotlib button_press_event events. Invoked every time a mouse button is pressed.

on_button_release_event(event)[source]

A handler for matplotlib button_release_event events. Invoked every time a mouse button is released.

on_key_press_event(event)[source]

A handler for matplotlib key_press_event events. Invoked every time a key is pressed.

If I is pressed pickign is enabled for all artists and a pick event is generated at cursor position.

on_motion_notify_event(event)[source]

A handler for matplotlib motion_notify_event events. Invoked every time mouse moves across the canvas or when a mouse button is released.

on_pick_event(event)[source]

A handler for matplotlib pick_event events. Invoked every time user picks a location close to some object.

resizeEvent(self, a0: QResizeEvent)[source]
set_repaint(state)[source]

Enable or disable repainting.

showCrosshair(state)[source]

Enable or disable drawing crosshair when mouse cursor moves inside a matplotlib axes.

showRubberband(state)[source]

Enable or disable rubberband drawing.

sizeHint(self) QSize[source]
class pyopus.plotter.plotwidget.QPOverlay(parent=None, enableCrosshair=True, enableRubberband=True)[source]

A transparent Qt widget that overlays crosshair and rubberband.

keyPressEvent(event)[source]

Key press event handler. Ignores the events so they get sent to the parent widget (the one that is under the overlay).

paintEvent(event)[source]

Repaints the overlay.

setCrosshair(pos)[source]

Set crosshair position pos (a tuple holding x,y coordinates). It is assumed y coordinate is inverted (increasing from bottom to top of the widget).

Ip pos is set to None crosshair is not displayed.

Calling this function schedules an update of the overlay.

setRubberband(pos0=None, pos=None)[source]

Set rubberband to be a rectangle between pos0 and pos. Both positions are tuples holding x,y coordinates. It is assumed y coordinate is inverted (increasing from bottom to top of the widget).

Ip pos0 or pos is set to None rubberband is not displayed.

Calling this function schedules an update of the overlay.

showCrosshair(state)[source]

Enable/disable crosshair.

showRubberband(state)[source]

Enable/disable rubberband.

class pyopus.plotter.plotwidget.QPPlotWindow(parent=None, title='Plot window', lock=None, **kwargs)[source]

A matplotlib canvas embedded in a PyQt window.

For parent see PyQt documentation.

title is the title of the window. See PyQt documentation for parent and id.

lock is a threading.Lock object that prevents other threads from accessing Matplotlib objects while PyQt events are handled. It is passed to the QPFigureCanvas object.

All remaining arguments are passed to the QPFigureCanvas constructor.

closeEvent(e)[source]

Just before the window is closed this handler is invoked. It emits a windowClosing signal.

createActions()[source]

Creates menu actions.

createStatusBar()[source]

Creates a statu sbar at the bottom of the window.

draw()[source]

Draw the associated Figure onto the screen. Shortcut to the QPFigureCanvas.draw() method.

getCanvas()[source]

Returns the QPFigureCanvas object associated with this window.

getFigure()[source]

Returns the MatPlotLib Figure associated with this canvas.

onAbout()[source]

Handles the Help/About option.

onClose()[source]

Handles the File/Close option.

onCloseAll()[source]

Handles the File/Close all windows option.

onFileSave()[source]

Handles File/Save option.

updateCoordinates(data)[source]

Updates the coordinates display in status bar.

windowClosing

This signal is emitted when the user requests closing of all plot windows.