Plot: Full plot API

Plot API for 1D and 2D data.

The Plot implements the plot API initially provided in PyMca.

Colormap

The Plot uses a dictionary to describe a colormap. This dictionary has the following keys:

  • ‘name’: str, name of the colormap. Available colormap are returned by

    Plot.getSupportedColormaps(). At least ‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’ are supported.

  • ‘normalization’: Either ‘linear’ or ‘log’

  • ‘autoscale’: bool, True to get bounds from the min and max of the

    data, False to use [vmin, vmax]

  • ‘vmin’: float, min value, ignored if autoscale is True

  • ‘vmax’: float, max value, ignored if autoscale is True

  • ‘colors’: optional, custom colormap.

    Nx3 or Nx4 numpy array of RGB(A) colors, either uint8 or float in [0, 1]. If ‘name’ is None, then this array is used as the colormap.

Plot Events

The Plot sends some event to the registered callback (See Plot.setCallback()). Those events are sent as a dictionary with a key ‘event’ describing the kind of event.

Drawing events

‘drawingProgress’ and ‘drawingFinished’ events are sent during drawing interaction (See Plot.setInteractiveMode()).

  • ‘event’: ‘drawingProgress’ or ‘drawingFinished’

  • ‘parameters’: dict of parameters used by the drawing mode.

    It has the following keys: ‘shape’, ‘label’, ‘color’. See Plot.setInteractiveMode().

  • ‘points’: Points (x, y) in data coordinates of the drawn shape.

    For ‘hline’ and ‘vline’, it is the 2 points defining the line. For ‘line’ and ‘rectangle’, it is the coordinates of the start drawing point and the latest drawing point. For ‘polygon’, it is the coordinates of all points of the shape.

  • ‘type’: The type of drawing in ‘line’, ‘hline’, ‘polygon’, ‘rectangle’,

    ‘vline’.

  • ‘xdata’ and ‘ydata’: X coords and Y coords of shape points in data

    coordinates (as in ‘points’).

When the type is ‘rectangle’, the following additional keys are provided:

  • ‘x’ and ‘y’: The origin of the rectangle in data coordinates
  • ‘widht’ and ‘height’: The size of the rectangle in data coordinates

Mouse events

‘mouseMoved’, ‘mouseClicked’ and ‘mouseDoubleClicked’ events are sent for mouse events.

They provide the following keys:

  • ‘event’: ‘mouseMoved’, ‘mouseClicked’ or ‘mouseDoubleClicked’
  • ‘button’: the mouse button that was pressed in ‘left’, ‘middle’, ‘right’
  • ‘x’ and ‘y’: The mouse position in data coordinates
  • ‘xpixel’ and ‘ypixel’: The mouse position in pixels

Marker events

‘hover’, ‘markerClicked’, ‘markerMoving’ and ‘markerMoved’ events are sent during interaction with markers.

‘hover’ is sent when the mouse cursor is over a marker. ‘markerClicker’ is sent when the user click on a selectable marker. ‘markerMoving’ and ‘markerMoved’ are sent when a draggable marker is moved.

They provide the following keys:

  • ‘event’: ‘hover’, ‘markerClicked’, ‘markerMoving’ or ‘markerMoved’
  • ‘button’: the mouse button that is pressed in ‘left’, ‘middle’, ‘right’
  • ‘draggable’: True if the marker is draggable, False otherwise
  • ‘label’: The legend associated with the clicked image or curve
  • ‘selectable’: True if the marker is selectable, False otherwise
  • ‘type’: ‘marker’
  • ‘x’ and ‘y’: The mouse position in data coordinates
  • ‘xdata’ and ‘ydata’: The marker position in data coordinates

‘markerClicked’ and ‘markerMoving’ events have a ‘xpixel’ and a ‘ypixel’ additional keys, that provide the mouse position in pixels.

Image and curve events

‘curveClicked’ and ‘imageClicked’ events are sent when a selectable curve or image is clicked.

Both share the following keys:

  • ‘event’: ‘curveClicked’ or ‘imageClicked’
  • ‘button’: the mouse button that was pressed in ‘left’, ‘middle’, ‘right’
  • ‘label’: The legend associated with the clicked image or curve
  • ‘type’: The type of item in ‘curve’, ‘image’
  • ‘x’ and ‘y’: The clicked position in data coordinates
  • ‘xpixel’ and ‘ypixel’: The clicked position in pixels

‘curveClicked’ events have a ‘xdata’ and a ‘ydata’ additional keys, that provide the coordinates of the picked points of the curve. There can be more than one point of the curve being picked, and if a line of the curve is picked, only the first point of the line is included in the list.

‘imageClicked’ have a ‘col’ and a ‘row’ additional keys, that provide the column and row index in the image array that was clicked.

Limits changed events

‘limitsChanged’ events are sent when the limits of the plot are changed. This can results from user interaction or API calls.

It provides the following keys:

  • ‘event’: ‘limitsChanged’
  • ‘source’: id of the widget that emitted this event.
  • ‘xdata’: Range of X in graph coordinates: (xMin, xMax).
  • ‘ydata’: Range of Y in graph coordinates: (yMin, yMax).
  • ‘y2data’: Range of right axis in graph coordinates (y2Min, y2Max) or None.

Plot state change events

The following events are emitted when the plot is modified. They provide the new state:

  • ‘setGraphCursor’ event with a ‘state’ key (bool)
  • ‘setGraphGrid’ event with a ‘which’ key (str), see setGraphGrid()
  • ‘setKeepDataAspectRatio’ event with a ‘state’ key (bool)
  • ‘setXAxisAutoScale’ event with a ‘state’ key (bool)
  • ‘setXAxisLogarithmic’ event with a ‘state’ key (bool)
  • ‘setYAxisAutoScale’ event with a ‘state’ key (bool)
  • ‘setYAxisInverted’ event with a ‘state’ key (bool)
  • ‘setYAxisLogarithmic’ event with a ‘state’ key (bool)

A ‘contentChanged’ event is triggered when the content of the plot is updated. It provides the following keys:

  • ‘action’: The change of the plot: ‘add’ or ‘remove’
  • ‘kind’: The kind of primitive changed: ‘curve’, ‘image’, ‘item’ or ‘marker’
  • ‘legend’: The legend of the primitive changed.

‘activeCurveChanged’ and ‘activeImageChanged’ events with the following keys:

  • ‘legend’: Name (str) of the current active item or None if no active item.

  • ‘previous’: Name (str) of the previous active item or None if no item was

    active. It is the same as ‘legend’ if ‘updated’ == True

  • ‘updated’: (bool) True if active item name did not changed,

    but active item data or style was updated.

‘interactiveModeChanged’ event with a ‘source’ key identifying the object setting the interactive mode.

Plot class

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

Bases: object

This class implements the plot API initially provided in PyMca.

Supported backends:

  • ‘matplotlib’ and ‘mpl’: Matplotlib with Qt.
  • ‘opengl’ and ‘gl’: OpenGL backend (requires PyOpenGL and OpenGL >= 2.1)
  • ‘none’: No backend, to run headless for testing purpose.
Parameters:
  • parent – The parent widget of the plot (Default: None)
  • backend – The backend to use. A str in: ‘matplotlib’, ‘mpl’, ‘opengl’, ‘gl’, ‘none’ or a BackendBase.BackendBase class
DEFAULT_BACKEND = 'matplotlib'

Class attribute setting the default backend for all instances.

getDataRange()[source]

Returns this Plot’s data range.

Returns:a namedtuple with the following members : x, y (left y axis), yright. Each member is a tuple (min, max) or None if no data is associated with the axis.
Return type:namedtuple
addCurve(x, y, legend=None, info=None, replace=False, replot=None, color=None, symbol=None, linewidth=None, linestyle=None, xlabel=None, ylabel=None, yaxis=None, xerror=None, yerror=None, z=None, selectable=None, fill=None, resetzoom=True, histogram=None, copy=True, **kw)[source]

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

Curves are uniquely identified by their legend. To add multiple curves, call addCurve() multiple times with different legend argument. To replace an existing curve, call addCurve() with the existing curve legend. If you want to display the curve values as an histogram see the histogram parameter or addHistogram().

When curve parameters are not provided, if a curve with the same legend is displayed in the plot, its parameters are used.

Parameters:
  • x (numpy.ndarray) – The data corresponding to the x coordinates. If you attempt to plot an histogram you can set edges values in x. In this case len(x) = len(y) + 1
  • y (numpy.ndarray) – The data corresponding to the y coordinates
  • legend (str) – The legend to be associated to the curve (or None)
  • info – User-defined information associated to the curve
  • replace (bool) – True (the default) to delete already existing curves
  • color (str (“#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:

    - 'o' circle
    - '.' point
    - ',' pixel
    - '+' cross
    - 'x' x-cross
    - 'd' diamond
    - 's' square
    - None (the default) to use default symbol
    
  • linewidth (float) – The width of the curve in pixels (Default: 1).
  • linestyle (str) –

    Type of line:

    - ' '  no line
    - '-'  solid line
    - '--' dashed line
    - '-.' dash-dot line
    - ':'  dotted line
    - None (the default) to use default line style
    
  • xlabel (str) – Label to show on the X axis when the curve is active or None to keep default axis label.
  • ylabel (str) – Label to show on the Y axis when the curve is active or None to keep default axis label.
  • yaxis (str) – The Y axis this curve is attached to. Either ‘left’ (the default) or ‘right’
  • xerror (A float, or a numpy.ndarray of float32. If it is an array, it can either be a 1D array of same length as the data or a 2D array with 2 rows of same length as the data: row 0 for positive errors, row 1 for negative errors.) – Values with the uncertainties on the x values
  • yerror (A float, or a numpy.ndarray of float32. See xerror.) – Values with the uncertainties on the y values
  • z (int) – Layer on which to draw the curve (default: 1) This allows to control the overlay.
  • selectable (bool) – Indicate if the curve can be selected. (Default: True)
  • fill (bool) – True to fill the curve, False otherwise (default).
  • resetzoom (bool) – True (the default) to reset the zoom.
  • histogram (str) –

    if not None then the curve will be draw as an histogram. The step for each values of the curve can be set to the left, center or right of the original x curve values. If histogram is not None and len(x) == len(y)+1 then x is directly take as edges of the histogram. Type of histogram:

    - None (default)
    - 'left'
    - 'right'
    - 'center'
    
  • copy (bool) – True make a copy of the data (default), False to use provided arrays.
Returns:

The key string identify this curve

addHistogram(histogram, edges, legend=None, color=None, fill=None, align='center', resetzoom=True, copy=True)[source]

Add an histogram to the graph.

This is NOT computing the histogram, this method takes as parameter already computed histogram values.

Histogram are uniquely identified by their legend. To add multiple histograms, call addHistogram() multiple times with different legend argument.

When histogram parameters are not provided, if an histogram with the same legend is displayed in the plot, its parameters are used.

Parameters:
  • histogram (numpy.ndarray) – The values of the histogram.
  • edges (numpy.ndarray) – The bin edges of the histogram. If histogram and edges have the same length, the bin edges are computed according to the align parameter.
  • legend (str) – The legend to be associated to the histogram (or None)
  • color (str (“#RRGGBB”) or RGB unsigned byte array or one of the predefined color names defined in Colors.py) – color to be used
  • fill (bool) – True to fill the curve, False otherwise (default).
  • align (str) – In case histogram values and edges have the same length N, the N+1 bin edges are computed according to the alignment in: ‘center’ (default), ‘left’, ‘right’.
  • resetzoom (bool) – True (the default) to reset the zoom.
  • copy (bool) – True make a copy of the data (default), False to use provided arrays.
Returns:

The key string identify this histogram

addImage(data, legend=None, info=None, replace=True, replot=None, xScale=None, yScale=None, z=None, selectable=None, draggable=None, colormap=None, pixmap=None, xlabel=None, ylabel=None, origin=None, scale=None, resetzoom=True, copy=True, **kw)[source]

Add a 2D dataset or an image to the plot.

It displays either an array of data using a colormap or a RGB(A) image.

Images are uniquely identified by their legend. To add multiple images, call addImage() multiple times with different legend argument. To replace/update an existing image, call addImage() with the existing image legend.

When image parameters are not provided, if an image with the same legend is displayed in the plot, its parameters are used.

Parameters:
  • data (numpy.ndarray) – (nrows, ncolumns) data or (nrows, ncolumns, RGBA) ubyte array
  • legend (str) – The legend to be associated to the image (or None)
  • info – User-defined information associated to the image
  • replace (bool) – True (default) to delete already existing images
  • z (int) – Layer on which to draw the image (default: 0) This allows to control the overlay.
  • selectable (bool) – Indicate if the image can be selected. (default: False)
  • draggable (bool) – Indicate if the image can be moved. (default: False)
  • colormap (dict) – Description of the colormap to use (or None) This is ignored if data is a RGB(A) image. See Plot for the documentation of the colormap dict.
  • pixmap ((nrows, ncolumns, RGBA) ubyte array or None (default)) – Pixmap representation of the data (if any)
  • xlabel (str) – X axis label to show when this curve is active, or None to keep default axis label.
  • ylabel (str) – Y axis label to show when this curve is active, or None to keep default axis label.
  • origin (float or 2-tuple of float) – (origin X, origin Y) of the data. It is possible to pass a single float if both coordinates are equal. Default: (0., 0.)
  • scale (float or 2-tuple of float) – (scale X, scale Y) of the data. It is possible to pass a single float if both coordinates are equal. Default: (1., 1.)
  • resetzoom (bool) – True (the default) to reset the zoom.
  • copy (bool) – True make a copy of the data (default), False to use provided arrays.
Returns:

The key string identify this image

addScatter(x, y, value, legend=None, colormap=None, info=None, symbol=None, xerror=None, yerror=None, z=None, copy=True)[source]

Add a (x, y, value) scatter to the graph.

Scatters are uniquely identified by their legend. To add multiple scatters, call addScatter() multiple times with different legend argument. To replace/update an existing scatter, call addScatter() with the existing scatter legend.

When scatter parameters are not provided, if a scatter with the same legend is displayed in the plot, its parameters are used.

Parameters:
  • x (numpy.ndarray) – The data corresponding to the x coordinates.
  • y (numpy.ndarray) – The data corresponding to the y coordinates
  • value (numpy.ndarray) – The data value associated with each point
  • legend (str) – The legend to be associated to the scatter (or None)
  • colormap (dict) – The colormap to be used for the scatter (or None) See Plot for the documentation of the colormap dict.
  • info – User-defined information associated to the curve
  • symbol (str) –

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

    - 'o' circle
    - '.' point
    - ',' pixel
    - '+' cross
    - 'x' x-cross
    - 'd' diamond
    - 's' square
    - None (the default) to use default symbol
    
  • xerror (A float, or a numpy.ndarray of float32. If it is an array, it can either be a 1D array of same length as the data or a 2D array with 2 rows of same length as the data: row 0 for positive errors, row 1 for negative errors.) – Values with the uncertainties on the x values
  • yerror (A float, or a numpy.ndarray of float32. See xerror.) – Values with the uncertainties on the y values
  • z (int) – Layer on which to draw the scatter (default: 1) This allows to control the overlay.
  • copy (bool) – True make a copy of the data (default), False to use provided arrays.
Returns:

The key string identify this scatter

addItem(xdata, ydata, legend=None, info=None, replace=False, shape='polygon', color='black', fill=True, overlay=False, z=None, **kw)[source]

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

Items are uniquely identified by their legend. To add multiple items, call addItem() multiple times with different legend argument. To replace/update an existing item, call addItem() with the existing item legend.

Parameters:
  • xdata (numpy.ndarray) – The X coords of the points of the shape
  • ydata (numpy.ndarray) – The Y coords of the points of the shape
  • legend (str) – The legend to be associated to the item
  • info – User-defined information associated to the item
  • replace (bool) – True (default) to delete already existing images
  • shape (str) – Type of item to be drawn in hline, polygon (the default), rectangle, vline, polylines
  • color (str) – Color of the item, e.g., ‘blue’, ‘b’, ‘#FF0000’ (Default: ‘black’)
  • fill (bool) – True (the default) to fill the shape
  • overlay (bool) – True if item is an overlay (Default: False). This allows for rendering optimization if this item is changed often.
  • z (int) – Layer on which to draw the item (default: 2)
Returns:

The key string identify this item

addXMarker(x, legend=None, text=None, color=None, selectable=False, draggable=False, constraint=None, **kw)[source]

Add a vertical line marker to the plot.

Markers are uniquely identified by their legend. As opposed to curves, images and items, two calls to addXMarker() without legend argument adds two markers with different identifying legends.

Parameters:
  • x (float) – Position of the marker on the X axis in data coordinates
  • legend (str) – Legend associated to the marker to identify it
  • text (str) – Text to display on the marker.
  • color (str) – Color of the marker, e.g., ‘blue’, ‘b’, ‘#FF0000’ (Default: ‘black’)
  • selectable (bool) – Indicate if the marker can be selected. (default: False)
  • draggable (bool) – Indicate if the marker can be moved. (default: False)
  • 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.
Returns:

The key string identify this marker

addYMarker(y, legend=None, text=None, color=None, selectable=False, draggable=False, constraint=None, **kw)[source]

Add a horizontal line marker to the plot.

Markers are uniquely identified by their legend. As opposed to curves, images and items, two calls to addYMarker() without legend argument adds two markers with different identifying legends.

Parameters:
  • y (float) – Position of the marker on the Y axis in data coordinates
  • legend (str) – Legend associated to the marker to identify it
  • text (str) – Text to display next to the marker.
  • color (str) – Color of the marker, e.g., ‘blue’, ‘b’, ‘#FF0000’ (Default: ‘black’)
  • selectable (bool) – Indicate if the marker can be selected. (default: False)
  • draggable (bool) – Indicate if the marker can be moved. (default: False)
  • 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.
Returns:

The key string identify this marker

addMarker(x, y, legend=None, text=None, color=None, selectable=False, draggable=False, symbol='+', constraint=None, **kw)[source]

Add a point marker to the plot.

Markers are uniquely identified by their legend. As opposed to curves, images and items, two calls to addMarker() without legend argument adds two markers with different identifying legends.

Parameters:
  • x (float) – Position of the marker on the X axis in data coordinates
  • y (float) – Position of the marker on the Y axis in data coordinates
  • legend (str) – Legend associated to the marker to identify it
  • text (str) – Text to display next to the marker
  • color (str) – Color of the marker, e.g., ‘blue’, ‘b’, ‘#FF0000’ (Default: ‘black’)
  • selectable (bool) – Indicate if the marker can be selected. (default: False)
  • draggable (bool) – Indicate if the marker can be moved. (default: False)
  • symbol (str) –

    Symbol representing the marker in:

    - 'o' circle
    - '.' point
    - ',' pixel
    - '+' cross (the default)
    - '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.
Returns:

The key string identify this marker

isCurveHidden(legend)[source]

Returns True if the curve associated to legend is hidden, else False

Parameters:legend (str) – The legend key identifying the curve
Returns:True if the associated curve is hidden, False otherwise
hideCurve(legend, flag=True, replot=None)[source]

Show/Hide the curve associated to legend.

Even when hidden, the curve is kept in the list of curves.

Parameters:
  • legend (str) – The legend associated to the curve to be hidden
  • flag (bool) – True (default) to hide the curve, False to show it
remove(legend=None, kind=('curve', 'image', 'scatter', 'item', 'marker', 'histogram'))[source]

Remove one or all element(s) of the given legend and kind.

Examples:

  • remove() clears the plot
  • remove(kind='curve') removes all curves from the plot
  • remove('myCurve', kind='curve') removes the curve with legend ‘myCurve’ from the plot.
  • remove('myImage, kind='image') removes the image with legend ‘myImage’ from the plot.
  • remove('myImage') removes elements (for instance curve, image, item and marker) with legend ‘myImage’.
Parameters:
  • legend (str) – The legend associated to the element to remove, or None to remove
  • kind (str or tuple of str to specify multiple kinds.) – The kind of elements to remove from the plot. In: ‘all’, ‘curve’, ‘image’, ‘item’, ‘marker’. By default, it removes all kind of elements.
removeCurve(legend)[source]

Remove the curve associated to legend from the graph.

Parameters:legend (str) – The legend associated to the curve to be deleted
removeImage(legend)[source]

Remove the image associated to legend from the graph.

Parameters:legend (str) – The legend associated to the image to be deleted
removeItem(legend)[source]

Remove the item associated to legend from the graph.

Parameters:legend (str) – The legend associated to the item to be deleted
removeMarker(legend)[source]

Remove the marker associated to legend from the graph.

Parameters:legend (str) – The legend associated to the marker to be deleted
clear()[source]

Remove everything from the plot.

clearCurves()[source]

Remove all the curves from the plot.

clearImages()[source]

Remove all the images from the plot.

clearItems()[source]

Remove all the items from the plot.

clearMarkers()[source]

Remove all the markers from the plot.

getGraphCursor()[source]

Returns the state of the crosshair cursor.

See setGraphCursor().

Returns:None if the crosshair cursor is not active, else a tuple (color, linewidth, linestyle).
setGraphCursor(flag=False, color='black', linewidth=1, linestyle='-')[source]

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

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

    Type of line:

    - ' ' no line
    - '-' solid line (the default)
    - '--' dashed line
    - '-.' dash-dot line
    - ':' dotted line
    
pan(direction, factor=0.1)[source]

Pan the graph in the given direction by the given factor.

Warning: Pan of right Y axis not implemented!

Parameters:
  • direction (str) – One of ‘up’, ‘down’, ‘left’, ‘right’.
  • factor (float) – Proportion of the range used to pan the graph. Must be strictly positive.
isActiveCurveHandling()[source]

Returns True if active curve selection is enabled.

setActiveCurveHandling(flag=True)[source]

Enable/Disable active curve selection.

Parameters:flag (bool) – True (the default) to enable active curve selection.
getActiveCurveColor()[source]

Get the color used to display the currently active curve.

See setActiveCurveColor().

setActiveCurveColor(color='#000000')[source]

Set the color to use to display the currently active curve.

Parameters:color (str) – Color of the active curve, e.g., ‘blue’, ‘b’, ‘#FF0000’ (Default: ‘black’)
getActiveCurve(just_legend=False)[source]

Return the currently active curve.

It returns None in case of not having an active curve.

Parameters:just_legend (bool) – True to get the legend of the curve, False (the default) to get the curve data and info.
Returns:Active curve’s legend or corresponding items.Curve
Return type:str or items.Curve or None
setActiveCurve(legend, replot=None)[source]

Make the curve associated to legend the active curve.

Parameters:legend (str or None) – The legend associated to the curve or None to have no active curve.
getActiveImage(just_legend=False)[source]

Returns the currently active image.

It returns None in case of not having an active image.

Parameters:just_legend (bool) – True to get the legend of the image, False (the default) to get the image data and info.
Returns:Active image’s legend or corresponding image object
Return type:str, items.ImageData, items.ImageRgba or None
setActiveImage(legend, replot=None)[source]

Make the image associated to legend the active image.

Parameters:legend (str) – The legend associated to the image or None to have no active image.
getAllCurves(just_legend=False, withhidden=False)[source]

Returns all curves legend or info and data.

It returns an empty list in case of not having any curve.

If just_legend is False, it returns a list of items.Curve objects describing the curves. If just_legend is True, it returns a list of curves’ legend.

Parameters:
  • just_legend (bool) – True to get the legend of the curves, False (the default) to get the curves’ data and info.
  • withhidden (bool) – False (default) to skip hidden curves.
Returns:

list of curves’ legend or items.Curve

Return type:

list of str or list of items.Curve

getCurve(legend=None)[source]

Get the object describing a specific curve.

It returns None in case no matching curve is found.

Parameters:legend (str) – The legend identifying the curve. If not provided or None (the default), the active curve is returned or if there is no active curve, the latest updated curve that is not hidden is returned if there are curves in the plot.
Returns:None or items.Curve object
getAllImages(just_legend=False)[source]

Returns all images legend or objects.

It returns an empty list in case of not having any image.

If just_legend is False, it returns a list of items.ImageBase objects describing the images. If just_legend is True, it returns a list of legends.

Parameters:just_legend (bool) – True to get the legend of the images, False (the default) to get the images’ object.
Returns:list of images’ legend or items.ImageBase
Return type:list of str or list of items.ImageBase
getImage(legend=None)[source]

Get the object describing a specific image.

It returns None in case no matching image is found.

Parameters:legend (str) – The legend identifying the image. If not provided or None (the default), the active image is returned or if there is no active image, the latest updated image is returned if there are images in the plot.
Returns:None or items.ImageBase object
getScatter(legend=None)[source]

Get the object describing a specific scatter.

It returns None in case no matching scatter is found.

Parameters:legend (str) – The legend identifying the scatter. If not provided or None (the default), the active scatter is returned or if there is no active scatter, the latest updated scatter is returned if there are scatters in the plot.
Returns:None or items.Scatter object
getHistogram(legend=None)[source]

Get the object describing a specific histogram.

It returns None in case no matching histogram is found.

Parameters:legend (str) – The legend identifying the histogram. If not provided or None (the default), the latest updated scatter is returned if there are histograms in the plot.
Returns:None or items.Histogram object
getGraphXLimits()[source]

Get the graph X (bottom) limits.

Returns:Minimum and maximum values of the X axis
setGraphXLimits(xmin, xmax, replot=None)[source]

Set the graph X (bottom) limits.

Parameters:
  • xmin (float) – minimum bottom axis value
  • xmax (float) – maximum bottom axis value
getGraphYLimits(axis='left')[source]

Get the graph Y limits.

Parameters:axis (str) – The axis for which to get the limits: Either ‘left’ or ‘right’
Returns:Minimum and maximum values of the X axis
setGraphYLimits(ymin, ymax, axis='left', replot=None)[source]

Set the graph Y limits.

Parameters:
  • ymin (float) – minimum bottom axis value
  • ymax (float) – maximum bottom axis value
  • axis (str) – The axis for which to get the limits: Either ‘left’ or ‘right’
setLimits(xmin, xmax, ymin, ymax, y2min=None, y2max=None)[source]

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

If y2min or y2max is None, the right Y axis limits are not updated.

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 or None (the default)
  • y2max (float) – maximum right axis value or None (the default)
getGraphTitle()[source]

Return the plot main title as a str.

setGraphTitle(title='')[source]

Set the plot main title.

Parameters:title (str) – Main title of the plot (default: ‘’)
getGraphXLabel()[source]

Return the current X axis label as a str.

setGraphXLabel(label='X')[source]

Set the plot X axis label.

The provided label can be temporarily replaced by the X label of the active curve if any.

Parameters:label (str) – The X axis label (default: ‘X’)
getGraphYLabel(axis='left')[source]

Return the current Y axis label as a str.

Parameters:axis (str) – The Y axis for which to get the label (left or right)
setGraphYLabel(label='Y', axis='left')[source]

Set the plot Y axis label.

The provided label can be temporarily replaced by the Y label of the active curve if any.

Parameters:
  • label (str) – The Y axis label (default: ‘Y’)
  • axis (str) – The Y axis for which to set the label (left or right)
setYAxisInverted(flag=True)[source]

Set the Y axis orientation.

Parameters:flag (bool) – True for Y axis going from top to bottom, False for Y axis going from bottom to top
isYAxisInverted()[source]

Return True if Y axis goes from top to bottom, False otherwise.

isXAxisLogarithmic()[source]

Return True if X axis scale is logarithmic, False if linear.

setXAxisLogarithmic(flag)[source]

Set the bottom X axis scale (either linear or logarithmic).

Parameters:flag (bool) – True to use a logarithmic scale, False for linear.
isYAxisLogarithmic()[source]

Return True if Y axis scale is logarithmic, False if linear.

setYAxisLogarithmic(flag)[source]

Set the Y axes scale (either linear or logarithmic).

Parameters:flag (bool) – True to use a logarithmic scale, False for linear.
isXAxisAutoScale()[source]

Return True if X axis is automatically adjusting its limits.

setXAxisAutoScale(flag=True)[source]

Set the X axis limits adjusting behavior of resetZoom().

Parameters:flag (bool) – True to resize limits automatically, False to disable it.
isYAxisAutoScale()[source]

Return True if Y axes are automatically adjusting its limits.

setYAxisAutoScale(flag=True)[source]

Set the Y axis limits adjusting behavior of resetZoom().

Parameters:flag (bool) – True to resize limits automatically, False to disable it.
isKeepDataAspectRatio()[source]

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

setKeepDataAspectRatio(flag=True)[source]

Set whether the plot keeps data aspect ratio or not.

Parameters:flag (bool) – True to respect data aspect ratio
getGraphGrid()[source]

Return the current grid mode, either None, ‘major’ or ‘both’.

See setGraphGrid().

setGraphGrid(which=True)[source]

Set the type of grid to display.

Parameters:which (str of bool) – None or False to disable the grid, ‘major’ or True for grid on major ticks (the default), ‘both’ for grid on both major and minor ticks.
isDefaultPlotPoints()[source]

Return True if default Curve symbol is ‘o’, False for no symbol.

setDefaultPlotPoints(flag)[source]

Set the default symbol of all curves.

When called, this reset the symbol of all existing curves.

Parameters:flag (bool) – True to use ‘o’ as the default curve symbol, False to use no symbol.
isDefaultPlotLines()[source]

Return True for line as default line style, False for no line.

setDefaultPlotLines(flag)[source]

Toggle the use of lines as the default curve line style.

Parameters:flag (bool) – True to use a line as the default line style, False to use no line as the default line style.
getDefaultColormap()[source]

Return the default colormap used by addImage() as a dict.

See Plot for the documentation of the colormap dict.

setDefaultColormap(colormap=None)[source]

Set the default colormap used by addImage().

Setting the default colormap do not change any currently displayed image. It only affects future calls to addImage() without the colormap parameter.

Parameters:colormap (dict) – The description of the default colormap, or None to set the colormap to a linear autoscale gray colormap. See Plot for the documentation of the colormap dict.
getSupportedColormaps()[source]

Get the supported colormap names as a tuple of str.

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

getWidgetHandle()[source]

Return the widget the plot is displayed in.

This widget is owned by the backend.

notify(event, **kwargs)[source]

Send an event to the listeners.

Event are passed to the registered callback as a dict with an ‘event’ key for backward compatibility with PyMca.

Parameters:
  • event (str) – The type of event
  • kwargs – The information of the event.
setCallback(callbackFunction=None)[source]

Attach a listener to the backend.

Limitation: Only one listener at a time.

Parameters:callbackFunction – function accepting a dictionary as input to handle the graph events If None (default), use a default listener.
graphCallback(ddict=None)[source]

This callback is going to receive all the events from the plot.

Those events will consist on a dictionary and among the dictionary keys the key ‘event’ is mandatory to describe the type of event. This default implementation only handles setting the active curve.

saveGraph(filename, fileFormat=None, dpi=None, **kw)[source]

Save a snapshot of the plot.

Supported file formats: “png”, “svg”, “pdf”, “ps”, “eps”, “tif”, “tiff”, “jpeg”, “jpg”.

Parameters:
  • filename (str, StringIO or BytesIO) – Destination
  • fileFormat (str) – String specifying the format
Returns:

False if cannot save the plot, True otherwise

getDataMargins()[source]

Get the default data margin ratios, see setDataMargins().

Returns:The margin ratios for each side (xMin, xMax, yMin, yMax).
Return type:A 4-tuple of floats.
setDataMargins(xMinMargin=0.0, xMaxMargin=0.0, yMinMargin=0.0, yMaxMargin=0.0)[source]

Set the default data margins to use in resetZoom().

Set the default ratios of margins (as floats) to add around the data inside the plot area for each side.

getAutoReplot()[source]

Return True if replot is automatically handled, False otherwise.

See :meth`setAutoReplot`.

setAutoReplot(autoreplot=True)[source]

Set automatic replot mode.

When enabled, the plot is redrawn automatically when changed. When disabled, the plot is not redrawn when its content change. Instead, it replot() must be called.

Parameters:autoreplot (bool) – True to enable it (default), False to disable it.
replot()[source]

Redraw the plot immediately.

resetZoom(dataMargins=None)[source]

Reset the plot limits to the bounds of the data and redraw the plot.

It automatically scale limits of axes that are in autoscale mode (See setXAxisAutoScale(), setYAxisAutoScale()). It keeps current limits on axes that are 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 (Default: no margins).
dataToPixel(x=None, y=None, axis='left', check=True)[source]

Convert a position in data coordinates to a position in pixels.

Parameters:
  • x (float) – The X coordinate in data space. If None (default) the middle position of the displayed data is used.
  • y (float) – The Y coordinate in data space. If None (default) the middle position of the displayed data is used.
  • axis (str) – The Y axis to use for the conversion (‘left’ or ‘right’).
  • check (bool) – True to return None if outside displayed area, False to convert to pixels anyway
Returns:

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

Return type:

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

pixelToData(x, y, axis='left', check=False)[source]

Convert a position in pixels to a position in data coordinates.

Parameters:
  • x (float) – The X coordinate in pixels. If None (default) the center of the widget is used.
  • y (float) – The Y coordinate in pixels. If None (default) the center of the widget is used.
  • axis (str) – The Y axis to use for the conversion (‘left’ or ‘right’).
  • check (bool) – Toggle checking if pixel is in plot area. If False, this method never returns None.
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.

getPlotBoundsInPixels()[source]

Plot area bounds in widget coordinates in pixels.

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

Set the cursor shape.

Parameters:cursor (str) – Name of the cursor shape
onMousePress(xPixel, yPixel, btn)[source]

Handle mouse press event.

Parameters:
  • xPixel (float) – X mouse position in pixels
  • yPixel (float) – Y mouse position in pixels
  • btn (str) – Mouse button in ‘left’, ‘middle’, ‘right’
onMouseMove(xPixel, yPixel)[source]

Handle mouse move event.

Parameters:
  • xPixel (float) – X mouse position in pixels
  • yPixel (float) – Y mouse position in pixels
onMouseRelease(xPixel, yPixel, btn)[source]

Handle mouse release event.

Parameters:
  • xPixel (float) – X mouse position in pixels
  • yPixel (float) – Y mouse position in pixels
  • btn (str) – Mouse button in ‘left’, ‘middle’, ‘right’
onMouseWheel(xPixel, yPixel, angleInDegrees)[source]

Handle mouse wheel event.

Parameters:
  • xPixel (float) – X mouse position in pixels
  • yPixel (float) – Y mouse position in pixels
  • angleInDegrees (float) – Angle corresponding to wheel motion. Positive for movement away from the user, negative for movement toward the user.
onMouseLeaveWidget()[source]

Handle mouse leave widget event.

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().

setInteractiveMode(mode, color='black', shape='polygon', label=None, zoomOnWheel=True, source=None, width=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’, ‘freeline’. Default is ‘polygon’.
  • label (str) – Only for ‘draw’ mode, sent in drawing events.
  • zoomOnWheel (bool) – Toggle zoom on wheel support
  • source – A user-defined object (typically the caller object) that will be send in the interactiveModeChanged event, to identify which object required a mode change. Default: None
  • width (float) – Width of the pencil. Only for draw pencil mode.
isDrawModeEnabled()[source]

Deprecated, use getInteractiveMode() instead.

Return True if the current interactive state is drawing.

setDrawModeEnabled(flag=True, shape='polygon', label=None, color=None, **kwargs)[source]

Deprecated, use setInteractiveMode() instead.

Set the drawing mode if flag is True and its parameters.

If flag is False, only item selection is enabled.

Warning: Zoom and drawing are not compatible and cannot be enabled simultaneously.

Parameters:
  • flag (bool) – True to enable drawing and disable zoom and select.
  • shape (str) – Type of item to be drawn in: hline, vline, rectangle, polygon (default)
  • label (str) – Associated text for identifying draw signals
  • color (string (“#RRGGBB”) or 4 column unsigned byte array or one of the predefined color names defined in Colors.py) – The color to use to draw the selection area
getDrawMode()[source]

Deprecated, use getInteractiveMode() instead.

Return the draw mode parameters as a dict of None.

It returns None if the interactive mode is not a drawing mode, otherwise, it returns a dict containing the drawing mode parameters as provided to setDrawModeEnabled().

isZoomModeEnabled()[source]

Deprecated, use getInteractiveMode() instead.

Return True if the current interactive state is zooming.

setZoomModeEnabled(flag=True, color=None)[source]

Deprecated, use setInteractiveMode() instead.

Set the zoom mode if flag is True, else item selection is enabled.

Warning: Zoom and drawing are not compatible and cannot be enabled simultaneously

Parameters:
  • flag (bool) – If True, enable zoom and select mode.
  • color (string (“#RRGGBB”) or 4 column unsigned byte array or one of the predefined color names defined in Colors.py) – The color to use to draw the selection area. (Default: ‘black’)
  • color – The color to use to draw the selection area
insertMarker(*args, **kwargs)[source]

Deprecated, use addMarker() instead.

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

Deprecated, use addXMarker() instead.

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

Deprecated, use addYMarker() instead.

isActiveCurveHandlingEnabled()[source]

Deprecated, use isActiveCurveHandling() instead.

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

Deprecated, use setActiveCurveHandling() instead.

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

Deprecated, use setYAxisInverted() instead.

showGrid(flag=True)[source]

Deprecated, use setGraphGrid() instead.

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

Deprecated, use setKeepDataAspectRatio().