PyMcaGraph Package

This package implements a graphics abstraction.

The abstraction itself is defined in PyMca5.PyMcaGraph.PlotBackend while PyMca5.PyMcaGraph.PlotBase implements a plugin interface.

The module PyMca5.PyMcaGraph.Plot implements all the previous via composition while adding a bookkeeping system. Actual plotting widgets will inherit PyMca5.PyMcaGraph.Plot

You can take a look at PyMca5.PyMcaGui.plotting.PlotWidget for a simple implementation using Qt. That implementation gets further improved adding toolbars and dock widgets in PyMca5.PyMcaGui.plotting.PlotWindow

Plot Module

This module can be used for plugin testing purposes as well as for doing the bookkeeping of actual plot windows.

Functions to be implemented by an actual plotter can be found in the abstract class PlotBackend.

class PyMca5.PyMcaGraph.Plot.Plot(parent=None, backend=None, callback=None)[source]

Bases: PyMca5.PyMcaGraph.PlotBase.PlotBase

PLUGINS_DIR = None
addCurve(x, y, legend=None, info=None, replace=False, replot=True, color=None, symbol=None, linestyle=None, xlabel=None, ylabel=None, yaxis=None, xerror=None, yerror=None, z=None, selectable=None, **kw)[source]
addImage(data, legend=None, info=None, replace=True, replot=True, xScale=None, yScale=None, z=None, selectable=False, draggable=False, colormap=None, pixmap=None, **kw)[source]
Parameters:
  • data (numpy.ndarray) – (nrows, ncolumns) data or (nrows, ncolumns, RGBA) ubyte array
  • legend (string or None) – The legend to be associated to the curve
  • info (dict or None) – Dictionary of information associated to the image
  • replace (boolean default True) – Flag to indicate if already existing images are to be deleted
  • replot (boolean default True) – Flag to indicate plot is to be immediately updated
  • xScale (list or numpy.ndarray) – Two floats defining the x scale
  • yScale (list or numpy.ndarray) – Two floats defining the y scale
  • z (A number bigger than or equal to zero (default)) – level at which the image is to be located (to allow overlays).
  • selectable (boolean, default False) – Flag to indicate if the image can be selected
  • draggable (boolean, default False) – Flag to indicate if the image can be moved
  • colormap (Dictionnary or None (default). Ignored if data is RGB(A)) – Dictionary describing the colormap to use (or None)
  • pixmap ((nrows, ncolumns, RGBA) ubyte array or None (default)) – Pixmap representation of the data (if any)
Returns:

The legend/handle used by the backend to univocally access it.

addItem(xdata, ydata, legend=None, info=None, replot=True, replace=False, shape='polygon', **kw)[source]
clear()[source]
clearCurves()[source]
clearImages()[source]

Clear all images from the plot. Not the curves or markers.

clearMarkers()[source]
colorDict = {'darkGreen': '#008000', 'brown': '#a52a2a', 'yellow': '#ffff00', 'violet': '#6600ff', 'magenta': '#ff00ff', 'darkMagenta': '#800080', 'blue': '#0000ff', 'black': '#000000', 'orange': '#ff9900', 'white': '#ffffff', 'red': '#ff0000', 'pink': '#ff66ff', 'darkCyan': '#008080', 'darkBlue': '#000080', 'darkBrown': '#660000', 'cyan': '#00ffff', 'gray': '#a0a0a4', 'c': '#00ffff', 'b': '#0000ff', 'g': '#00ff00', 'k': '#000000', 'm': '#ff00ff', 'grey': '#a0a0a4', 'darkRed': '#800000', 'r': '#ff0000', 'green': '#00ff00', 'darkYellow': '#808000', 'y': '#ffff00'}
colorList = ['#000000', '#0000ff', '#ff0000', '#00ff00', '#ff66ff', '#ffff00', '#a52a2a', '#00ffff', '#ff00ff', '#ff9900', '#6600ff', '#a0a0a4', '#000080', '#800000', '#008000', '#008080', '#800080', '#808000', '#660000']
dataToPixel(x=None, y=None, axis='left')[source]

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

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

defaultBackend

alias of PlotBackend

enableActiveCurveHandling(flag=True)[source]
enableMarkerMode(flag)[source]
getActiveCurve(just_legend=False)[source]
Parameters:just_legend (boolean) – Flag to specify the type of output required
Returns:legend of the active curve or list [x, y, legend, info]
Return type:string or list

Function to access the graph currently active curve. It returns None in case of not having an active curve.

Default output has the form:
xvalues, yvalues, legend, dict where dict is a dictionnary containing curve info. For the time being, only the plot labels associated to the curve are warranted to be present under the keys xlabel, ylabel.
If just_legend is True:
The legend of the active curve (or None) is returned.
getActiveImage(just_legend=False)[source]
Parameters:just_legend (boolean) – Flag to specify the type of output required
Returns:legend of the active image or list [data, legend, info, xScale, yScale, z]
Return type:string or list

Function to access the plot currently active image. It returns None in case of not having an active image.

Default output has the form:
data, legend, dict, xScale, yScale, z where dict is a dictionnary containing image info. For the time being, only the plot labels associated to the image are warranted to be present under the keys xlabel, ylabel.
If just_legend is True:
The legend of the active imagee (or None) is returned.
getAllCurves(just_legend=False)[source]
Parameters:just_legend (boolean) – Flag to specify the type of output required
Returns:legend of the curves or list [[x, y, legend, info], ...]
Return type:list of strings or list of curves

It returns an empty list in case of not having any curve. If just_legend is False:

It returns a list of the form:
[[xvalues0, yvalues0, legend0, dict0],
[xvalues1, yvalues1, legend1, dict1], [...], [xvaluesn, yvaluesn, legendn, dictn]]

or just an empty list.

If just_legend is True:
It returns a list of the form:
[legend0, legend1, ..., legendn]

or just an empty list.

getCurve(legend)[source]
Parameters:legend (boolean) – legend associated to the curve
Returns:list [x, y, legend, info]
Return type:list

Function to access the graph specified curve. It returns None in case of not having the curve.

Default output has the form:
xvalues, yvalues, legend, info where info is a dictionnary containing curve info. For the time being, only the plot labels associated to the curve are warranted to be present under the keys xlabel, ylabel.
getDefaultColormap()[source]

Return the colormap that will be applied by the backend to an image if no colormap is applied to it. A colormap is a dictionnary with the keys: :type name: string :type normalization: string (linear, log) :type autoscale: boolean :type vmin: float, minimum value :type vmax: float, maximum value :type colors: integer (typically 256)

getDrawMode()[source]

Return a dictionnary (or None) with the parameters passed when setting the draw mode. :key shape: The shape being drawn :key label: Associated text (or None) and any other info

getGraphTitle()[source]
getGraphXLabel()[source]
getGraphXLimits()[source]

Get the graph X (bottom) limits. :return: Minimum and maximum values of the X axis

getGraphYLabel()[source]
getGraphYLimits()[source]

Get the graph Y (left) limits. :return: Minimum and maximum values of the X axis

getImage(legend)[source]
Parameters:legend (boolean) – legend associated to the curve
Returns:list [image, legend, info, pixmap]
Return type:list

Function to access the graph currently active curve. It returns None in case of not having an active curve.

Default output has the form:
image, legend, info, pixmap where info is a dictionnary containing image information.
getSupportedColormaps()[source]

Get a list of strings with the colormap names supported by the backend. The list should at least contain and start by: [‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’]

getWidgetHandle()[source]
graphCallback(ddict=None)[source]

This callback is foing to receive all the events from the plot. Those events will consist on a dictionnary and among the dictionnary keys the key ‘event’ is mandatory to describe the type of event. This default implementation only handles setting the active curve.

hideCurve(legend, flag=True, replot=True)[source]
insertMarker(x, y, legend=None, text=None, color=None, selectable=False, draggable=False, **kw)[source]
insertXMarker(x, legend=None, text=None, color=None, selectable=False, draggable=False, **kw)[source]

kw ->symbol

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

kw -> color, symbol

invertYAxis(flag=True)[source]
isCurveHidden(legend)[source]
isDrawModeEnabled()[source]
isMarkerModeEnabled(flag)[source]
isXAxisAutoScale()[source]
isXAxisLogarithmic()[source]
isYAxisAutoScale()[source]
isYAxisInverted()[source]
isYAxisLogarithmic()[source]
isZoomModeEnabled()[source]
keepDataAspectRatio(flag=True)[source]
Parameters:flag (Boolean, default True) – True to respect data aspect ratio
logFilterData(x, y, xLog=None, yLog=None, color=None)[source]
pixelToData(x=None, y=None, axis='left')[source]

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

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

removeCurve(legend, replot=True)[source]

Remove the curve associated to the supplied legend from the graph. The graph will be updated if replot is true. :param legend: The legend associated to the curve to be deleted :type legend: string or None :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

removeImage(legend, replot=True)[source]

Remove the image associated to the supplied legend from the graph. The graph will be updated if replot is true. :param legend: The legend associated to the image to be deleted :type legend: string or handle :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

removeItem(legend, replot=True)[source]
removeMarker(marker)[source]
replot()[source]
resetZoom()[source]
saveGraph(filename, fileFormat='svg', dpi=None, **kw)[source]
Parameters:
  • fileName (String or StringIO or BytesIO) – Destination
  • fileFormat (String (default 'svg')) – String specifying the format
setActiveCurve(legend, replot=True)[source]

Funtion to request the plot window to set the curve with the specified legend as the active curve. :param legend: The legend associated to the curve :type legend: string

setActiveCurveColor(color='#000000')[source]
setActiveImage(legend, replot=True)[source]

Funtion to request the plot window to set the image with the specified legend as the active image. :param legend: The legend associated to the image :type legend: string

setCallback(callbackFunction)[source]
setDefaultColormap(colormap=None)[source]

Sets the colormap that will be applied by the backend to an image if no colormap is applied to it. A colormap is a dictionnary with the keys: :type name: string :type normalization: string (linear, log) :type autoscale: boolean :type vmin: float, minimum value :type vmax: float, maximum value :type colors: integer (typically 256)

If None is passed, the backend will reset to its default colormap.

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

Zoom and drawing are not compatible and cannot be enabled simultanelously

Parameters:
  • flag (boolean, default True) – Enable drawing mode disabling zoom and picking mode
  • shape (string (default polygon)) – Type of item to be drawn (line, hline, vline, rectangle...)
  • label (string, default None) – Associated text (for identifying the 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
setGraphTitle(title='')[source]
setGraphXLabel(label='X')[source]
setGraphXLimits(xmin, xmax, replot=False)[source]
setGraphYLabel(label='Y')[source]
setGraphYLimits(ymin, ymax, replot=False)[source]
setMarkerFollowMouse(marker, boolean)[source]
setXAxisAutoScale(flag=True)[source]
setXAxisLogarithmic(flag)[source]
setYAxisAutoScale(flag=True)[source]
setYAxisLogarithmic(flag)[source]
setZoomModeEnabled(flag=True, color='black')[source]

Zoom and drawing are not compatible and cannot be enabled simultanelously

Parameters:
  • flag (boolean, default True) – If True, the user can zoom.
  • 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
showGrid(flag=True)[source]
PyMca5.PyMcaGraph.Plot.main()[source]

PlotBackend Module

This module can be used for testing purposes as well as an abstract class for implementing Plot backends.

TODO: Still to be worked out: handling of the right vertical axis.

PlotBackend Functions (Functions marked by (*) only needed for handling images)

  • addCurve
  • addImage (*)
  • addItem (*)
  • clear
  • clearCurves
  • clearImages (*)
  • clearMarkers
  • enableActiveCurveHandling
  • getDefaultColormap (*)
  • getDrawMode
  • getGraphXLabel
  • getGraphXLimits
  • getGraphYLabel
  • getGraphYLimits
  • getGraphTitle
  • getSupportedColormaps (*)
  • getWidgetHandle
  • insertMarker
  • insertXMarker
  • insertYMarker
  • invertYAxis
  • isDrawModeEnabled
  • isXAxisAutoScale
  • isYAxisAutoScale
  • keepDataAspectRatio(*)
  • removeCurve
  • removeImage (*)
  • removeMarker
  • resetZoom
  • replot
  • replot_
  • saveGraph
  • setActiveCurve
  • setActiveImage (*)
  • setCallback
  • setDefaultColormap (*)
  • setDrawModeEnabled
  • setGraphTitle
  • setGraphXLabel
  • setGraphXLimits
  • setGraphYLabel
  • setGraphYLimits
  • setLimits
  • setXAxisAutoScale
  • setXAxisLogarithmic
  • setYAxisAutoScale
  • setYAxisLogarithmic
  • setZoomModeEnabled
  • showGrid

PlotBackend “signals/events”

All the events pass via the callback_function supplied.

They consist on a dictionnary in which the ‘event’ key is mandatory.

The following keys will be present or not depending on the type of event, but if present, their meaning should be:

KEY - Meaning

  • button - “left”, “right”, “middle”
  • label - The label or legend associated to the item associated to the event
  • type - The type of item associated to event (‘curve’, ‘marker’, ...)
  • x - Bottom axis value in graph coordenates
  • y - Vertical axis value in graph coordenates
  • xpixel - x position in pixel coordenates
  • ypixel - y position in pixel coordenates
  • xdata - Horizontal graph coordinate associated to the item
  • ydata - Vertical graph coordinate associated to the item

drawingFinished

It looks as it should export xdata, ydata and type.

The information will depend on the type of item being drawn:

  • line - two points in graph and pixel coordinates
  • hline - one point in graph and pixel coordinates
  • vline - one point in graph and pixel coordinates
  • rectangle - four points in graph and pixel coordinates, x, y, width, height
  • polygone - n points in graph and pixel coordinates
  • ellipse - four points in graph and pixel coordinates?
  • circle - four points in graph and pixel coordinates, center and radius
  • parameters - Parameters passed to setDrawMode when enabling it
hover
Emitted the mouse pass over an item with hover notification (markers)
imageClicked, curveClicked
usefull for pop-up menus associated to the click using the xpixel, ypixel or to set a curve active using the label and type keys
markerMoving

Additional keys:

  • draggable - True if it is a movable marker (it should be True)
  • selectable - True if the marker can be selected
markerMoved

Additional keys:

  • draggable - True if it is a movable marker (it should be True)
  • selectable - True if the marker can be selected
  • xdata, ydata - Final position of the marker
markerClicked

Additional keys:

  • draggable - True if it is a movable marker
  • selectable - True if the marker can be selected (it should be True)
mouseMoved
Export the mouse position in pixel and graph coordenates
mouseClicked
Emitted on mouse release when not zooming, nor drawing, nor picking
mouseDoubleClicked
Emitted on mouse release when not zooming, nor drawing, nor picking
MouseZoom

TODO: NOT USED? Figure out how to implement a limitsChanged signal?

keys xmin, xmax, ymin, ymax in graph coordenates keys xpixel_min, xpixel_max, ypixel_min, ypixel_max in pixel coordenates

class PyMca5.PyMcaGraph.PlotBackend.PlotBackend(parent=None)[source]

Bases: object

COLORDICT = {'darkGreen': '#008000', 'brown': '#a52a2a', 'yellow': '#ffff00', 'violet': '#6600ff', 'magenta': '#ff00ff', 'darkMagenta': '#800080', 'blue': '#0000ff', 'black': '#000000', 'orange': '#ff9900', 'white': '#ffffff', 'red': '#ff0000', 'pink': '#ff66ff', 'darkCyan': '#008080', 'darkBlue': '#000080', 'darkBrown': '#660000', 'cyan': '#00ffff', 'gray': '#a0a0a4', 'c': '#00ffff', 'b': '#0000ff', 'g': '#00ff00', 'k': '#000000', 'm': '#ff00ff', 'grey': '#a0a0a4', 'darkRed': '#800000', 'r': '#ff0000', 'green': '#00ff00', 'darkYellow': '#808000', 'y': '#ffff00'}

Dictionnary of predefined colors

addCurve(x, y, legend=None, info=None, replace=False, replot=True, color=None, symbol=None, linestyle=None, xlabel=None, ylabel=None, yaxis=None, xerror=None, yerror=None, z=1, selectable=True, **kw)

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

Parameters:
  • x (list or numpy.ndarray) – The data corresponding to the x axis
  • y (list or numpy.ndarray) – The data corresponding to the y axis
  • legend (string or None) – The legend to be associated to the curve
  • info (dict or None) – Dictionary of information associated to the curve
  • replace (boolean default False) – Flag to indicate if already existing curves are to be deleted
  • replot (boolean default True) – Flag to indicate plot is to be immediately updated
  • 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 (None or one of the predefined symbols) –

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

    - 'o' circle
    - '.' point
    - ',' pixel
    - '+' cross
    - 'x' x-cross
    - 'd' diamond
    - 's' square
    
  • linestyle (None or one of the predefined styles.) –

    Type of line:

    - ' '  no line
    - '-'  solid line
    - '--' dashed line
    - '-.' dash-dot line
    - ':'  dotted line
    
  • xlabel (array) – Label associated to the X axis when the curve is active
  • ylabel (array) – Label associated to the Y axis when the curve is active
  • yaxis (string or None) – Anything different from “right” is equivalent to “left”
  • xerror – Values with the uncertainties on the x values
  • yerror – Values with the uncertainties on the y values
  • z (A number bigger than or equal to zero (default: one)) – level at which the curve is to be located (to allow overlays).
  • selectable (boolean default: True) – indicate if the curve can be picked.
Returns:

The legend/handle used by the backend to univocally access it.

addImage(data, legend=None, info=None, replace=True, replot=True, xScale=None, yScale=None, z=0, selectable=False, draggable=False, colormap=None, **kw)
Parameters:
  • data (numpy.ndarray) – (nrows, ncolumns) data or (nrows, ncolumns, RGBA) ubyte array
  • legend (string or None) – The legend to be associated to the curve
  • info (dict or None) – Dictionary of information associated to the image
  • replace (boolean default True) – Flag to indicate if already existing images are to be deleted
  • replot (boolean default True) – Flag to indicate plot is to be immediately updated
  • xScale (list or numpy.ndarray) – Two floats defining the x scale
  • yScale (list or numpy.ndarray) – Two floats defining the y scale
  • z (A number bigger than or equal to zero (default)) – level at which the image is to be located (to allow overlays).
  • selectable (boolean, default False) – Flag to indicate if the image can be selected
  • draggable (boolean, default False) – Flag to indicate if the image can be moved
  • colormap (Dictionnary or None (default). Ignored if data is RGB(A)) – Dictionary describing the colormap to use (or None)
Returns:

The legend/handle used by the backend to univocally access it.

addItem(xList, yList, legend=None, info=None, replace=False, replot=True, shape='polygon', fill=True, **kw)
Parameters:shape (string, default polygon) – Type of item to be drawn
clear()

Clear all curvers and other items from the plot

clearCurves()

Clear all curves from the plot. Not the markers!!

clearImages()

Clear all images from the plot. Not the curves or markers.

clearMarkers()

Clear all markers from the plot. Not the curves!!

dataToPixel(x=None, y=None, axis='left')

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

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

enableActiveCurveHandling(flag=True)
getDefaultColormap()

Return the colormap that will be applied by the backend to an image if no colormap is applied to it.

A colormap is a dictionnary with the keys:

  • name: string
  • normalization: string (linear, log)
  • autoscale: boolean
  • vmin: float, minimum value
  • vmax: float, maximum value
  • colors: integer (typically 256)
getDrawMode()

Return a dictionnary (or None) with the parameters passed when setting the draw mode.

  • shape: The shape being drawn
  • label: Associated text (or None)

and any other info passed to setDrawMode

getGraphTitle()

Get the graph title. :return: string

getGraphXLabel()

Get the graph X (bottom) label. :return: string

getGraphXLimits()

Get the graph X (bottom) limits. :return: Minimum and maximum values of the X axis

getGraphYLabel()

Get the graph Y (left) label. :return: string

getGraphYLimits(axis='left')

Get the graph Y (left) limits.

Parameters:axis (str, either "left" (default) or "right") – The axis for which to get the limits
Returns:Minimum and maximum values of the Y axis
getSupportedColormaps()

Get a list of strings with the colormap names supported by the backend. The list should at least contain and start by: [‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’]

getWidgetHandle()
Returns:Backend widget or None if the backend inherits from widget.
insertMarker(x, y, legend=None, text=None, color='k', selectable=False, draggable=False, replot=True, **kw)
Parameters:
  • x (float) – Horizontal position of the marker in graph coordenates
  • y (float) – Vertical position of the marker in graph coordenates
  • legend (string) – Legend associated to the marker to identify it
  • text (string or None) – Text associated to the marker
  • color (string, default 'k' (black)) – Color to be used for instance ‘blue’, ‘b’, ‘#FF0000’
  • selectable (boolean, default False) – Flag to indicate if the marker can be selected
  • draggable (boolean, default False) – Flag to indicate if the marker can be moved
  • replot (boolean, default True) – Flag to indicate if the plot is to be updated
Returns:

Handle used by the backend to univocally access the marker

insertXMarker(x, legend=None, text=None, color='k', selectable=False, draggable=False, replot=True, **kw)
Parameters:
  • x (float) – Horizontal position of the marker in graph coordenates
  • legend (string) – Legend associated to the marker to identify it
  • text (string or None) – Text associated to the marker
  • color (string, default 'k' (black)) – Color to be used for instance ‘blue’, ‘b’, ‘#FF0000’
  • selectable (boolean, default False) – Flag to indicate if the marker can be selected
  • draggable (boolean, default False) – Flag to indicate if the marker can be moved
  • replot (boolean, default True) – Flag to indicate if the plot is to be updated
Returns:

Handle used by the backend to univocally access the marker

insertYMarker(y, legend=None, text=None, color='k', selectable=False, draggable=False, replot=True, **kw)
Parameters:
  • y (float) – Vertical position of the marker in graph coordenates
  • legend (string) – Legend associated to the marker to identify it
  • text (string or None) – Text associated to the marker
  • color (string, default 'k' (black)) – Color to be used for instance ‘blue’, ‘b’, ‘#FF0000’
  • selectable (boolean, default False) – Flag to indicate if the marker can be selected
  • draggable (boolean, default False) – Flag to indicate if the marker can be moved
  • replot (boolean, default True) – Flag to indicate if the plot is to be updated
Returns:

Handle used by the backend to univocally access the marker

invertYAxis(flag=True)
Parameters:flag (boolean) – If True, put the vertical axis origin on plot top left
isDrawModeEnabled()
Returns:True if user can draw
isXAxisAutoScale()
Returns:True if bottom axis is automatically adjusting the scale
isYAxisAutoScale()
Returns:True if left axis is automatically adjusting the scale
isYAxisInverted()
Returns:True if left axis is inverted
isZoomModeEnabled()
Returns:True if user can zoom
keepDataAspectRatio(flag=True)
Parameters:flag (Boolean, default True) – True to respect data aspect ratio
pixelToData(x=None, y=None, axis='left')

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

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

removeCurve(legend, replot=True)

Remove the curve associated to the supplied legend from the graph. The graph will be updated if replot is true. :param legend: The legend associated to the curve to be deleted :type legend: string or handle :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

removeImage(legend, replot=True)

Remove the image associated to the supplied legend from the graph. The graph will be updated if replot is true. :param legend: The legend associated to the image to be deleted :type legend: string or handle :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

removeItem(legend, replot=True)
removeMarker(label, replot=True)

Remove the marker associated to the supplied handle from the graph. The graph will be updated if replot is true. :param label: The handle/label associated to the curve to be deleted :type label: string or handle :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

replot()

Update plot. If replot is a reserved word of the used backend, it can be implemented as replot_

resetZoom()

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

saveGraph(fileName, fileFormat='svg', dpi=None, **kw)
Parameters:
  • fileName (String or StringIO or BytesIO) – Destination
  • fileFormat (String (default 'svg')) – String specifying the format
setActiveCurve(legend, replot=True)

Make the curve identified by the supplied legend active curve. :param legend: The legend associated to the curve :type legend: string :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

setActiveCurveColor(color='#000000')
setActiveImage(legend, replot=True)

Make the image identified by the supplied legend active. :param legend: The legend associated to the image :type legend: string :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

setCallback(callback_function)
Parameters:callback_function (callable) – function accepting a dictionnary as input to handle the graph events
setDefaultColormap(colormap=None)

Sets the colormap that will be applied by the backend to an image if no colormap is applied to it.

A colormap is a dictionnary with the keys:

If None is passed, the backend will reset to its default colormap.

setDrawModeEnabled(flag=True, shape='polygon', label=None, color=None, **kw)

Zoom and drawing are not compatible and cannot be enabled simultanelously

Parameters:
  • flag (boolean, default True) – Enable drawing mode disabling zoom and picking mode
  • shape (string (default polygon)) – Type of item to be drawn (line, hline, vline, rectangle...)
  • label (string, default None) – Associated text (for identifying the 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
setGraphTitle(title='')
Parameters:title (string, default is an empty string) – Title associated to the plot
setGraphXLabel(label='X')
Parameters:label (string, default is 'X') – label associated to the plot bottom axis
setGraphXLimits(xmin, xmax)
Parameters:
  • xmin (float) – minimum bottom axis value
  • xmax (float) – maximum bottom axis value
setGraphYLabel(label='Y')
Parameters:label (string, default is 'Y') – label associated to the plot left axis
setGraphYLimits(ymin, ymax, axis='left')
Parameters:
  • ymin (float) – minimum left axis value
  • ymax (float) – maximum left axis value
  • axis (str, either "left" (default) or "right") – The axis for which to set the limits
setLimits(xmin, xmax, ymin, ymax)

Convenience method

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
setXAxisAutoScale(flag=True)
Parameters:flag (boolean, default True) – If True, the bottom axis will adjust scale on zomm reset
setXAxisLogarithmic(flag=True)
Parameters:flag (boolean, default True) – If True, the bottom axis will use a log scale
setYAxisAutoScale(flag=True)
Parameters:flag (boolean, default True) – If True, the left axis will adjust scale on zomm reset
setYAxisLogarithmic(flag)
Parameters:flag (boolean) – If True, the left axis will use a log scale
setZoomModeEnabled(flag=True, color=None)

Zoom and drawing cannot be simultaneously enabled.

Parameters:
  • flag (boolean, default True) – If True, the user can zoom.
  • 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 (optional) color to use to draw the selection area.
showGrid(flag=True)
Parameters:flag (boolean, default True) – If True, the grid will be shown.
PyMca5.PyMcaGraph.PlotBackend.main()[source]

PlotBase Module

Any plot window willing to accept plugins should implement the methods defined in this class.

That way the plot will respect the Plot backend interface besides additional methods: The plugins will be compatible with any plot window that provides the methods:

getActiveCurve getActiveImage getAllCurves getCurve getImage getMonotonicCurves hideCurve hideImage isActiveCurveHandlingEnabled isCurveHidden isImageHidden printGraph setActiveCurve showCurve showImage

The simplest way to achieve that is to inherit from Plot

class PyMca5.PyMcaGraph.PlotBase.PlotBase(parent=None)[source]

Bases: PyMca5.PyMcaGraph.PlotBackend.PlotBackend, PyMca5.PyMcaGraph.PluginLoader.PluginLoader

getActiveCurve(just_legend=False)[source]
Parameters:just_legend (boolean) – Flag to specify the type of output required
Returns:legend of the active curve or list [x, y, legend, info]
Return type:string or list

Function to access the graph currently active curve. It returns None in case of not having an active curve.

Default output has the form:
xvalues, yvalues, legend, dict where dict is a dictionnary containing curve info. For the time being, only the plot labels associated to the curve are warranted to be present under the keys xlabel, ylabel.
If just_legend is True:
The legend of the active curve (or None) is returned.
getActiveImage(just_legend=False)[source]
getAllCurves(just_legend=False)[source]
Parameters:just_legend (boolean) – Flag to specify the type of output required
Returns:legend of the curves or list [[x, y, legend, info], ...]
Return type:list of strings or list of curves

It returns an empty list in case of not having any curve. If just_legend is False:

It returns a list of the form:
[[xvalues0, yvalues0, legend0, dict0],
[xvalues1, yvalues1, legend1, dict1], [...], [xvaluesn, yvaluesn, legendn, dictn]]

or just an empty list.

If just_legend is True:
It returns a list of the form:
[legend0, legend1, ..., legendn]

or just an empty list.

getCurve(legend)[source]
Parameters:legend (boolean) – legend associated to the curve
Returns:list [x, y, legend, info]
Return type:list

Function to access the graph specified curve. It returns None in case of not having the curve.

Default output has the form:
xvalues, yvalues, legend, info where info is a dictionnary containing curve info. For the time being, only the plot labels associated to the curve are warranted to be present under the keys xlabel, ylabel.
getImage(legend)[source]
Parameters:legend (boolean) – legend associated to the curve
Returns:list [image, legend, info, pixmap]
Return type:list

Function to access the graph specified image. It returns None in case of not having that image.

Default output has the form:
image, legend, info, pixmap where info is a dictionnary containing image information.
getMonotonicCurves()[source]

Convenience method that calls getAllCurves and makes sure that all of the X values are strictly increasing. :return: It returns a list of the form:

[[xvalues0, yvalues0, legend0, dict0],
[xvalues1, yvalues1, legend1, dict1], [...], [xvaluesn, yvaluesn, legendn, dictn]]
hideCurve(legend, replot=True)[source]

Remove the curve associated to the legend form the graph. It is still kept in the list of curves. The graph will be updated if replot is true. :param legend: The legend associated to the curve to be hidden :type legend: string or handle :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

hideImage(legend, replot=True)[source]

Remove the image associated to the supplied legend from the graph. I is still kept in the list of curves. The graph will be updated if replot is true. :param legend: The legend associated to the image to be hidden :type legend: string or handle :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

isActiveCurveHandlingEnabled()[source]
isCurveHidden(legend)[source]
Parameters:legend (string or handle) – The legend associated to the curve
Returns:True if the associated curve is hidden
isImageHidden(legend)[source]
Parameters:legend (string or handle) – The legend associated to the image
Returns:True if the associated image is hidden
printGraph(**kw)[source]
setActiveCurve(legend)[source]

Funtion to request the plot window to set the curve with the specified legend as the active curve. :param legend: The legend associated to the curve :type legend: string

showCurve(legend, replot=True)[source]

Show the curve associated to the legend in the graph. :param legend: The legend associated to the curve :type legend: string :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

showImage(legend, replot=True)[source]

Show the image associated to the legend in the graph. :param legend: The legend associated to the image :type legend: string :param replot: Flag to indicate plot is to be immediately updated :type replot: boolean default True

PluginLoader Module

Class to handle loading of plugins according to target method.

On instantiation, this clase imports all the plugins found in the PLUGINS_DIR directory and stores them into the attributes pluginList and pluginInstanceDict

class PyMca5.PyMcaGraph.PluginLoader.PluginLoader(method=None, directoryList=None)[source]

Bases: object

getPluginDirectoryList()[source]
Return dirlist:List of directories for searching plugins
getPlugins(method=None, directoryList=None, exceptions=False)[source]

Import or reloads all the available plugins with the target method

Parameters:
  • method (string, default "getPlugin1DInstance") – The method to be searched for.
  • directoryList (list or None (default).) – The list of directories for the search.
  • exceptions (boolean (default False)) – If True, return the list of error messages
Returns:

The number of plugins loaded. If exceptions is True, also the text with the error encountered.

setPluginDirectoryList(dirlist)[source]
Parameters:dirlist (list) – Set directories to search for plugins
PyMca5.PyMcaGraph.PluginLoader.main(targetMethod, directoryList)[source]