Package structure

The silx.gui.plot package provides a 1D, 2D plot widget that supports multiple backends. This package is structured as follows.

PlotWidget and PlotWindow provides the user API. PlotWidget is a Qt widget (actually a QMainWindow) displaying a 1D, 2D plot area. It provides different interaction modes. PlotWindow is a Qt widget (actually a QMainWindow) which adds a set of toolbar buttons and associated functionalities to PlotWidget. The toolbar QActions are implemented in PlotActions.

Plot, PlotEvents and PlotInteraction implement the plotting API regardless of the rendering backend and regardless of its integration in Qt. The plotting API in defined in Plot. The different interaction modes (zoom, drawing, pan) are implemented in PlotInteraction. Each interaction mode is implemented with a state machine structure (implemented in Interaction). The different events emitted by Plot and by the interaction modes are created with helper functions defined in PlotEvents.

BackendBase defines the API any plot backend should provide in BackendBase. BackendMatplotlib implements a matplotlib backend. It is splitted in two classes:

Modules

For PlotWidget and Plot modules, see their respective documentations: PlotWidget, Plot.

The following modules are the modules used internally by the plot package.

BackendBase

Base class for Plot backends.

It documents the Plot backend API.

This API is a simplified version of PyMca PlotBackend API.

class silx.gui.plot.BackendBase.BackendBase(plot, parent=None)[source]

Class defining the API a backend of the Plot should provide.

addCurve(x, y, legend, color, symbol, linewidth, linestyle, yaxis, xerror, yerror, z, selectable, fill)[source]

Add a 1D curve given by x an y to the graph.

Parameters:
  • x (numpy.ndarray) – The data corresponding to the x axis
  • y (numpy.ndarray) – The data corresponding to the y axis
  • legend (str) – The legend to be associated to the curve
  • color (string (“#RRGGBB”) or (npoints, 4) unsigned byte array or one of the predefined color names defined in Colors.py) – color(s) to be used
  • symbol (str) –

    Symbol to be drawn at each (x, y) position:

    - ' ' or '' no symbol
    - 'o' circle
    - '.' point
    - ',' pixel
    - '+' cross
    - 'x' x-cross
    - 'd' diamond
    - 's' square
    
  • linewidth (float) –

    The width of the curve in pixels

    • ‘ ‘ or ‘’ no line
    • ‘-‘ solid line
    • ‘–’ dashed line
    • ‘-.’ dash-dot line
    • ‘:’ dotted line
  • yaxis (str) – The Y axis this curve belongs to in: ‘left’, ‘right’
  • xerror (numpy.ndarray or None) – Values with the uncertainties on the x values
  • yerror (numpy.ndarray or None) – Values with the uncertainties on the y values
  • z (int) – Layer on which to draw the cuve
  • selectable (bool) – indicate if the curve can be selected
Returns:

The handle used by the backend to univocally access the curve

addImage(data, legend, origin, scale, z, selectable, draggable, colormap)[source]

Add an image to the plot.

Parameters:
  • data (numpy.ndarray) – (nrows, ncolumns) data or (nrows, ncolumns, RGBA) ubyte array
  • legend (str) – The legend to be associated to the image
  • origin (2-tuple of float) – (origin X, origin Y) of the data. Default: (0., 0.)
  • scale (2-tuple of float) – (scale X, scale Y) of the data. Default: (1., 1.)
  • z (int) – Layer on which to draw the image
  • selectable (bool) – indicate if the image can be selected
  • draggable (bool) – indicate if the image can be moved
  • colormap (dict or None) – Dictionary describing the colormap to use. Ignored if data is RGB(A).
Returns:

The handle used by the backend to univocally access the image

addItem(x, y, legend, shape, color, fill, overlay)[source]

Add an item (i.e. a shape) to the plot.

Parameters:
  • x (numpy.ndarray) – The X coords of the points of the shape
  • y (numpy.ndarray) – The Y coords of the points of the shape
  • legend (str) – The legend to be associated to the item
  • shape (str) – Type of item to be drawn in hline, polygon, rectangle, vline
  • fill (bool) – True to fill the shape
  • overlay (bool) – True if item is an overlay, False otherwise
Returns:

The handle used by the backend to univocally access the item

addMarker(x, y, legend, text, color, selectable, draggable, symbol, constraint, overlay)[source]

Add a point, vertical line or horizontal line marker to the plot.

Parameters:
  • x (float) – Horizontal position of the marker in graph coordinates. If None, the marker is a horizontal line.
  • y (float) – Vertical position of the marker in graph coordinates. If None, the marker is a vertical line.
  • legend (str) – Legend associated to the marker
  • text (str) – Text associated to the marker (or None for no text)
  • color (str) – Color to be used for instance ‘blue’, ‘b’, ‘#FF0000’
  • selectable (bool) – indicate if the marker can be selected
  • draggable (bool) – indicate if the marker can be moved
  • symbol (str) –

    Symbol representing the marker. Only relevant for point markers where X and Y are not None. Value in:

    • ‘o’ circle
    • ‘.’ point
    • ‘,’ pixel
    • ‘+’ cross
    • ‘x’ x-cross
    • ‘d’ diamond
    • ‘s’ square
  • constraint (None or a callable that takes the coordinates of the current cursor position in the plot as input and that returns the filtered coordinates.) – A function filtering marker displacement by dragging operations or None for no filter. This function is called each time a marker is moved. This parameter is only used if draggable is True.
  • overlay (bool) – True if marker is an overlay (Default: False). This allows for rendering optimization if this marker is changed often.
Returns:

Handle used by the backend to univocally access the marker

dataToPixel(x, y, axis)[source]

Convert a position in data space to a position in pixels in the widget.

Parameters:
  • x (float) – The X coordinate in data space.
  • y (float) – The Y coordinate in data space.
  • axis (str) – The Y axis to use for the conversion (‘left’ or ‘right’).
Returns:

The corresponding position in pixels or None if the data position is not in the displayed area.

Return type:

A tuple of 2 floats: (xPixel, yPixel) or None.

getGraphXLimits()[source]

Get the graph X (bottom) limits.

Returns:Minimum and maximum values of the X axis
getGraphYLimits(axis)[source]

Get the graph Y (left) limits.

Parameters:axis (str) – The axis for which to get the limits: left or right
Returns:Minimum and maximum values of the Y axis
getPlotBoundsInPixels()[source]

Plot area bounds in widget coordinates in pixels.

Returns:bounds as a 4-tuple of int: (left, top, width, height)
getSupportedColormaps()[source]

Get a list of strings with the supported colormap names.

The list should at least contain and start by: [‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’]

getWidgetHandle()[source]

Return the widget this backend is drawing to.

isKeepDataAspectRatio()[source]

Returns whether the plot is keeping data aspect ratio or not.

isYAxisInverted()[source]

Return True if left Y axis is inverted, False otherwise.

pickItems(x, y)[source]

Get a list of items at a pixel position.

Parameters:
  • x (float) – The x pixel coord where to pick.
  • y (float) – The y pixel coord where to pick.
Returns:

All picked items from back to front. One dict per item, with ‘kind’ key in ‘curve’, ‘marker’, ‘image’; ‘legend’ key, the item legend. and for curves, ‘xdata’ and ‘ydata’ keys storing picked position on the curve.

Return type:

list of dict

pixelToData(x, y, axis)[source]

Convert a position in pixels in the widget to a position in the data space.

Parameters:
  • x (float) – The X coordinate in pixels.
  • y (float) – The Y coordinate in pixels.
  • axis (str) – The Y axis to use for the conversion (‘left’ or ‘right’).
Returns:

The corresponding position in data space or None if the pixel position is not in the plot area.

Return type:

A tuple of 2 floats: (xData, yData) or None.

postRedisplay()[source]

Trigger a Plot.replot().

Default implementation triggers a synchronous replot if plot is dirty. This method should be overridden by the embedding widget in order to provide an asynchronous call to replot in order to optimize the number replot operations.

remove(item)[source]

Remove an existing item from the plot.

Parameters:item – A backend specific item handle returned by a add* method
replot()[source]

Redraw the plot.

resetZoom(dataMargins)[source]

Reset the displayed area of the plot.

Autoscale any axis that is in autoscale mode. Keep current limits on axes not in autoscale mode

Extra margins can be added around the data inside the plot area. Margins are given as one ratio of the data range per limit of the data (xMin, xMax, yMin and yMax limits). For log scale, extra margins are applied in log10 of the data.

Parameters:dataMargins (A 4-tuple of float as (xMin, xMax, yMin, yMax).) – Ratios of margins to add around the data inside the plot area for each side
saveGraph(fileName, fileFormat, dpi)[source]

Save the graph to a file (or a StringIO)

Parameters:
  • fileName (String or StringIO or BytesIO) – Destination
  • fileFormat (str) – String specifying the format
  • dpi (int) – The resolution to use or None.
setActiveCurve(curve, active, color=None)[source]

Set/Reset the color of a curve to show that it is active.

Parameters:
  • curve – The curve handle
  • active (bool) – True to set curve to color, False to reset curve to its initial color.
  • color (str) – The color to use.
setGraphCursor(flag, color, linewidth, linestyle)[source]

Toggle the display of a crosshair cursor and set its attributes.

To override in interactive backends.

Parameters:
  • flag (bool) – Toggle the display of a crosshair cursor.
  • color (A string (either a predefined color name in Colors.py or “#RRGGBB”)) or a 4 columns unsigned byte array.) – The color to use for the crosshair.
  • linewidth (int) – The width of the lines of the crosshair.
  • linestyle (None or one of the predefined styles.) –

    Type of line:

    - ' ' no line
    - '-' solid line
    - '--' dashed line
    - '-.' dash-dot line
    - ':' dotted line
    
setGraphCursorShape(cursor)[source]

Set the cursor shape.

To override in interactive backends.

Parameters:cursor (str) – Name of the cursor shape or None
setGraphGrid(which)[source]

Set grid.

Parameters:which – None to disable grid, ‘major’ for major grid, ‘both’ for major and minor grid
setGraphTitle(title)[source]

Set the main title of the plot.

Parameters:title (str) – Title associated to the plot
setGraphXLabel(label)[source]

Set the X axis label.

Parameters:label (str) – label associated to the plot bottom X axis
setGraphXLimits(xmin, xmax)[source]

Set the limits of X axis.

Parameters:
  • xmin (float) – minimum bottom axis value
  • xmax (float) – maximum bottom axis value
setGraphYLabel(label, axis)[source]

Set the left Y axis label.

Parameters:
  • label (str) – label associated to the plot left Y axis
  • axis (str) – The axis for which to get the limits: left or right
setGraphYLimits(ymin, ymax, axis)[source]

Set the limits of the Y axis.

Parameters:
  • ymin (float) – minimum left axis value
  • ymax (float) – maximum left axis value
  • axis (str) – The axis for which to get the limits: left or right
setKeepDataAspectRatio(flag)[source]

Set whether to keep data aspect ratio or not.

Parameters:flag (Boolean, default True) – True to respect data aspect ratio
setLimits(xmin, xmax, ymin, ymax, y2min=None, y2max=None)[source]

Set the limits of the X and Y axes at once.

Parameters:
  • xmin (float) – minimum bottom axis value
  • xmax (float) – maximum bottom axis value
  • ymin (float) – minimum left axis value
  • ymax (float) – maximum left axis value
  • y2min (float) – minimum right axis value
  • y2max (float) – maximum right axis value
setXAxisLogarithmic(flag)[source]

Set the X axis scale between linear and log.

Parameters:flag (bool) – If True, the bottom axis will use a log scale
setYAxisInverted(flag)[source]

Invert the Y axis.

Parameters:flag (bool) – If True, put the vertical axis origin on the top
setYAxisLogarithmic(flag)[source]

Set the Y axis scale between linear and log.

Parameters:flag (bool) – If True, the left axis will use a log scale

BackendMatplotlib

Matplotlib Plot backend.

class silx.gui.plot.BackendMatplotlib.BackendMatplotlib(plot, parent=None)[source]

Base class for Matplotlib backend without a FigureCanvas.

For interactive on screen plot, see BackendMatplotlibQt.

See BackendBase.BackendBase for public API documentation.

replot()[source]

Do not perform rendering.

Override in subclass to actually draw something.

class silx.gui.plot.BackendMatplotlib.BackendMatplotlibQt(plot, parent=None)[source]

QWidget matplotlib backend using a QtAgg canvas.

It adds fast overlay drawing and mouse event management.

draw()[source]

Override canvas draw method to support faster draw of overlays.

ColormapDialog

A QDialog widget to set-up the colormap.

It uses a description of colormaps as dict compatible with Plot.

To run the following sample code, a QApplication must be initialized.

Create the colormap dialog and set the colormap description and data range:

>>> from silx.gui.plot.ColormapDialog import ColormapDialog
>>> dialog = ColormapDialog()
>>> dialog.setColormap(name='red', normalization='log',
...                    autoscale=False, vmin=1., vmax=2.)
>>> dialog.setDataRange(1., 100.)  # This scale the width of the plot area
>>> dialog.show()

Get the colormap description (compatible with Plot) from the dialog:

>>> cmap = dialog.getColormap()
>>> cmap['name']
'red'

It is also possible to display an histogram of the image in the dialog. This updates the data range with the range of the bins.

>>> import numpy
>>> image = numpy.random.normal(size=512 * 512).reshape(512, -1)
>>> hist, bin_edges = numpy.histogram(image, bins=10)
>>> dialog.setHistogram(hist, bin_edges)

The updates of the colormap description are also available through the signal: ColormapDialog.sigColormapChanged.

class silx.gui.plot.ColormapDialog.ColormapDialog(title='Colormap Dialog', parent=None)[source]

A QDialog widget to set the colormap.

Parameters:
  • title (str) – The QDialog title
  • parent – See QDialog
getColormap()[source]

Return the colormap description as a dict.

See Plot for documentation on the colormap dict.

getDataRange()[source]

Returns the data range used for the histogram area.

Returns:(dataMin, dataMax) or None if no data range is set
Return type:2-tuple of float
getHistogram()[source]

Returns the counts and bin edges of the displayed histogram.

Returns:(hist, bin_edges)
Return type:2-tuple of numpy arrays
keyPressEvent(event)[source]

Override key handling.

It disables leaving the dialog when editing a text field.

setColormap(name=None, normalization=None, autoscale=None, vmin=None, vmax=None, colors=None)[source]

Set the colormap description

If some arguments are not provided, the current values are used.

Parameters:
  • name (str) – The name of the colormap
  • normalization (str) – ‘linear’ or ‘log’
  • autoscale (bool) – Toggle colormap range autoscale
  • vmin (float) – The min value, ignored if autoscale is True
  • vmax (float) – The max value, ignored if autoscale is True
setDataRange(min_=None, max_=None)[source]

Set the range of data to use for the range of the histogram area.

Parameters:
  • min (float) – The min of the data or None to disable range.
  • max (float) – The max of the data or None to disable range.
setHistogram(hist=None, bin_edges=None)[source]

Set the histogram to display.

This update the data range with the bounds of the bins. See setDataRange().

Parameters:
  • hist – array-like of counts or None to hide histogram
  • bin_edges – array-like of bins edges or None to hide histogram
sigColormapChanged

Signal triggered when the colormap is changed.

It provides a dict describing the colormap to the slot. This dict can be used with Plot.

Colors

Color conversion function and dictionary.

silx.gui.plot.Colors.rgba(color, colorDict=None)[source]

Convert color code ‘#RRGGBB’ and ‘#RRGGBBAA’ to (R, G, B, A)

Parameters:
  • code (str) – The color code to conver
  • colorDict (dict) – A dictionary of color name conversion to color code
Returns:

RGBA colors as floats in [0., 1.]

Return type:

tuple

Interaction

This module provides an implementation of state machines for interaction.

Sample code of a state machine with two states (‘idle’ and ‘active’) with transitions on left button press/release:

from silx.gui.plot.Interaction import *

class SampleStateMachine(StateMachine):

    class Idle(State):
        def onPress(self, x, y, btn):
            if btn == LEFT_BTN:
                self.goto('active')

    class Active(State):
        def enter(self):
            print('Enabled')  # Handle enter active state here

        def leave(self):
            print('Disabled')  # Handle leave active state here

        def onRelease(self, x, y, btn):
            if btn == LEFT_BTN:
                self.goto('idle')

def __init__(self):
    # State machine has 2 states
    states = {
        'idle': SampleStateMachine.Idle,
        'active': SampleStateMachine.Active
    }
    super(TwoStates, self).__init__(states, 'idle')
    # idle is the initial state

stateMachine = SampleStateMachine()

# Triggers a transition to the Active state:
stateMachine.handleEvent('press', 0, 0, LEFT_BTN)

# Triggers a transition to the Idle state:
stateMachine.handleEvent('release', 0, 0, LEFT_BTN)

See ClickOrDrag for another example of a state machine.

See Renaud Blanch, Michel Beaudouin-Lafon. Programming Rich Interactions using the Hierarchical State Machine Toolkit. In Proceedings of AVI 2006. p 51-58. for a discussion of using (hierarchical) state machines for interaction.

class silx.gui.plot.Interaction.ClickOrDrag[source]

State machine for left and right click and left drag interaction.

It is intended to be used through subclassing by overriding click(), beginDrag(), drag() and endDrag().

beginDrag(x, y)[source]

Called at the beginning of a drag gesture with left button pressed.

To override in a subclass.

click(x, y, btn)[source]

Called upon a left or right button click.

To override in a subclass.

drag(x, y)[source]

Called on mouse moved during a drag gesture.

To override in a subclass.

endDrag(x, y)[source]

Called at the end of a drag gesture when the left button is released.

To override in a subclass.

silx.gui.plot.Interaction.LEFT_BTN = 'left'

Left mouse button.

silx.gui.plot.Interaction.MIDDLE_BTN = 'middle'

Middle mouse button.

silx.gui.plot.Interaction.RIGHT_BTN = 'right'

Right mouse button.

class silx.gui.plot.Interaction.State(machine)[source]

Base class for the states of a state machine.

This class is meant to be subclassed.

enter(*args, **kwargs)[source]

Called when the state machine enters this state.

Arguments are those provided to the goto() method that triggered the transition to this state.

goto(state, *args, **kwargs)[source]

Performs a transition to a new state.

Extra arguments are passed to the enter() method of the new state.

Parameters:state (str) – The name of the state to go to.
leave()[source]

Called when the state machine leaves this state (i.e., when goto() is called).

machine[source]

The state machine this state belongs to.

Useful to access data or methods that are shared across states.

class silx.gui.plot.Interaction.StateMachine(states, initState, *args, **kwargs)[source]

State machine controller.

This is the entry point of a state machine. It is in charge of dispatching received event and handling the current active state.

handleEvent(eventName, *args, **kwargs)[source]

Process an event with the state machine.

This method looks up for an event handler in the current state and then in the StateMachine instance. Handler are looked up as ‘onEventName’ method. If a handler is found, it is called with the provided extra arguments, and this method returns the return value of the handler. If no handler is found, this method returns None.

Parameters:eventName (str) – Name of the event to handle
Returns:The return value of the handler or None

ModestImage

Matplotlib computationally modest image class.

class silx.gui.plot.ModestImage.ModestImage(*args, **kwargs)[source]

Computationally modest image class.

Customization of https://github.com/ChrisBeaumont/ModestImage to allow extent support.

ModestImage is an extension of the Matplotlib AxesImage class better suited for the interactive display of larger images. Before drawing, ModestImage resamples the data array based on the screen resolution and view window. This has very little affect on the appearance of the image, but can substantially cut down on computation since calculations of unresolved or clipped pixels are skipped.

The interface of ModestImage is the same as AxesImage. However, it does not currently support setting the ‘extent’ property. There may also be weird coordinate warping operations for images that I’m not aware of. Don’t expect those to work either.

draw(renderer, *args, **kwargs)[source]
get_array()[source]

Override to return the full-resolution array

get_image_extent()[source]

Returns the extent of the whole image.

get_extent returns the extent of the drawn area and not of the full image.

Returns:Bounds of the image (x0, x1, y0, y1).
Return type:Tuple of 4 floats.
set_data(A)[source]

Set the image array

ACCEPTS: numpy/PIL Image A

set_extent(extent)[source]

PlotActions

This module provides a set of QAction to use with PlotWidget.

The following QAction are available:

class silx.gui.plot.PlotActions.ColormapAction(plot, parent=None)[source]

QAction opening a ColormapDialog to update the colormap.

Both the active image colormap and the default colormap are updated.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
class silx.gui.plot.PlotActions.CopyAction(plot, parent=None)[source]

QAction to copy PlotWidget content to clipboard.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
copyPlot()[source]

Copy plot content to the clipboard as a bitmap.

class silx.gui.plot.PlotActions.CurveStyleAction(plot, parent=None)[source]

QAction controlling curve style on a PlotWidget.

It changes the default line and markers style which updates all curves on the plot.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
class silx.gui.plot.PlotActions.GridAction(plot, gridMode='both', parent=None)[source]

QAction controlling grid mode on a PlotWidget.

Parameters:
class silx.gui.plot.PlotActions.KeepAspectRatioAction(plot, parent=None)[source]

QAction controlling aspect ratio on a PlotWidget.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
class silx.gui.plot.PlotActions.PrintAction(plot, parent=None)[source]

QAction for printing the plot.

It opens a Print dialog.

Current implementation print a bitmap of the plot area and not vector graphics, so printing quality is not great.

Parameters:
  • plotPlotWidget instance on which to operate.
  • parent – See QAction.
printPlot()[source]

Open the print dialog and print the plot.

Use Plot.saveGraph() to print the plot.

Returns:True if successful
printPlotAsWidget()[source]

Open the print dialog and print the plot.

Use QWidget.render() to print the plot

Returns:True if successful
class silx.gui.plot.PlotActions.ResetZoomAction(plot, parent=None)[source]

QAction controlling reset zoom on a PlotWidget.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
class silx.gui.plot.PlotActions.SaveAction(plot, parent=None)[source]

QAction for saving Plot content.

It opens a Save as... dialog.

Parameters:
  • plotPlotWidget instance on which to operate.
  • parent – See QAction.
class silx.gui.plot.PlotActions.XAxisAutoScaleAction(plot, parent=None)[source]

QAction controlling X axis autoscale on a PlotWidget.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
class silx.gui.plot.PlotActions.XAxisLogarithmicAction(plot, parent=None)[source]

QAction controlling X axis log scale on a PlotWidget.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
class silx.gui.plot.PlotActions.YAxisAutoScaleAction(plot, parent=None)[source]

QAction controlling Y axis autoscale on a PlotWidget.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
class silx.gui.plot.PlotActions.YAxisInvertedAction(plot, parent=None)[source]

QAction controlling Y orientation on a PlotWidget.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction
class silx.gui.plot.PlotActions.YAxisLogarithmicAction(plot, parent=None)[source]

QAction controlling Y axis log scale on a PlotWidget.

Parameters:
  • plotPlotWidget instance on which to operate
  • parent – See QAction

PlotEvents

Functions to prepare events to be sent to Plot callback.

silx.gui.plot.PlotEvents.prepareCurveSignal(button, label, type_, xData, yData, x, y, xPixel, yPixel)[source]

See Plot documentation for content of events

silx.gui.plot.PlotEvents.prepareDrawingSignal(event, type_, points, parameters=None)[source]

See Plot documentation for content of events

silx.gui.plot.PlotEvents.prepareHoverSignal(label, type_, posData, posPixel, draggable, selectable)[source]

See Plot documentation for content of events

silx.gui.plot.PlotEvents.prepareImageSignal(button, label, type_, col, row, x, y, xPixel, yPixel)[source]

See Plot documentation for content of events

silx.gui.plot.PlotEvents.prepareLimitsChangedSignal(sourceObj, xRange, yRange, y2Range)[source]

See Plot documentation for content of events

silx.gui.plot.PlotEvents.prepareMarkerSignal(eventType, button, label, type_, draggable, selectable, posDataMarker, posPixelCursor=None, posDataCursor=None)[source]

See Plot documentation for content of events

silx.gui.plot.PlotEvents.prepareMouseSignal(eventType, button, xData, yData, xPixel, yPixel)[source]

See Plot documentation for content of events

PlotInteraction

Implementation of the interaction for the Plot.

class silx.gui.plot.PlotInteraction.FocusManager(eventHandlers=())[source]

Manages focus across multiple event handlers

On press an event handler can acquire focus. By default it looses focus when all buttons are released.

class silx.gui.plot.PlotInteraction.Pan(plot)[source]

Pan plot content and zoom on wheel state machine.

class silx.gui.plot.PlotInteraction.PlotInteraction(plot)[source]

Proxy to currently use state machine for interaction.

This allows to switch interactive mode.

Parameters:plot – The Plot to apply interaction to
getInteractiveMode()[source]

Returns the current interactive mode as a dict.

The returned dict contains at least the key ‘mode’. Mode can be: ‘draw’, ‘pan’, ‘select’, ‘zoom’. It can also contains extra keys (e.g., ‘color’) specific to a mode as provided to setInteractiveMode().

handleEvent(event, *args, **kwargs)[source]

Forward event to current interactive mode state machine.

setInteractiveMode(mode, color='black', shape='polygon', label=None)[source]

Switch the interactive mode.

Parameters:
  • mode (str) – The name of the interactive mode. In ‘draw’, ‘pan’, ‘select’, ‘zoom’.
  • color (Color description: The name as a str or a tuple of 4 floats.) – Only for ‘draw’ and ‘zoom’ modes. Color to use for drawing selection area. Default black.
  • shape (str) – Only for ‘draw’ mode. The kind of shape to draw. In ‘polygon’, ‘rectangle’, ‘line’, ‘vline’, ‘hline’. Default is ‘polygon’.
  • label (str) – Only for ‘draw’ mode.
zoomOnWheel = None

True to enable zoom on wheel, False otherwise.

class silx.gui.plot.PlotInteraction.Select(plot, parameters, states, state)[source]

Base class for drawing selection areas.

class silx.gui.plot.PlotInteraction.Select1Point(plot, parameters)[source]

Base class for drawing selection area based on one input point.

class silx.gui.plot.PlotInteraction.Select2Points(plot, parameters)[source]

Base class for drawing selection based on 2 input points.

class silx.gui.plot.PlotInteraction.SelectHLine(plot, parameters)[source]

Drawing a horizontal line selection area state machine.

class silx.gui.plot.PlotInteraction.SelectLine(plot, parameters)[source]

Drawing line selection area state machine.

class silx.gui.plot.PlotInteraction.SelectPolygon(plot, parameters)[source]

Drawing selection polygon area state machine.

class silx.gui.plot.PlotInteraction.SelectRectangle(plot, parameters)[source]

Drawing rectangle selection area state machine.

class silx.gui.plot.PlotInteraction.SelectVLine(plot, parameters)[source]

Drawing a vertical line selection area state machine.

class silx.gui.plot.PlotInteraction.Zoom(plot, color)[source]

Zoom-in/out state machine.

Zoom-in on selected area, zoom-out on right click, and zoom on mouse wheel.

class silx.gui.plot.PlotInteraction.ZoomAndSelect(plot, color)[source]

Combine Zoom and ItemInteraction state machine.

Table Of Contents

Previous topic

PlotWindow

Next topic

qt: Qt bindings

This Page