Adding 1D plugins

Overview

A 1D plugin is a module that can be added to the PyMca 1D window in order to perform user defined operations of the plotted 1D data.

Plugins can be automatically installed provided they are in the appropriate place:

  • In the user home directory: ${HOME}/PyMca/plugins (POSIX systems)
  • In “My Documents\PyMca\plugins” (Windows)

A plugin inherit the Plugin1DBase class and implement the methods:

and modify the static module variable MENU_TEXT and the static module function getPlugin1DInstance() according to the defined plugin.

These plugins will be compatible with any 1D-plot window that implements the Plot1D interface. The plot window interface is described in the Plot1DBase class.

The main items are reproduced here and can be directly accessed as plugin methods.

A simple plugin example, normalizing each curve to its maximum and vertically shifting the curves.

from PyMca5 import Plugin1DBase

class Shifting(Plugin1DBase.Plugin1DBase):
    def getMethods(self, plottype=None):
        return ["Shift"]

    def getMethodToolTip(self, methodName):
        if methodName != "Shift":
            raise InvalidArgument("Method %s not valid" % methodName)
        return "Subtract minimum, normalize to maximum, and shift up by 0.1"

    def applyMethod(self, methodName):
        if methodName != "Shift":
            raise ValueError("Method %s not valid" % methodName)
        allCurves = self.getAllCurves()
        increment = 0.1
        for i in range(len(allCurves)):
            x, y, legend, info = allCurves[i][:4]
            delta = float(y.max() - y.min())
            if delta < 1.0e-15:
                delta = 1.0
            y = (y - y.min())/delta + i * increment
            if i == (len(allCurves) - 1):
                replot = True
            else:
                replot = False
            if i == 0:
                replace = True
            else:
                replace = False
            self.addCurve(x, y, legend=legend + " %.2f" % (i * increment),
                                info=info, replace=replace, replot=replot)

MENU_TEXT="Simple Shift Example"
def getPlugin1DInstance(plotWindow, **kw):
    ob = Shifting(plotWindow)
    return ob

1D plugin API

class PyMca5.PyMcaCore.Plugin1DBase.Plugin1DBase(plotWindow, **kw)[source]
addCurve(x, y, legend=None, info=None, replace=False, replot=True, **kw)[source]

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
  • kw – Additional keywords recognized by the plot window. Beware that the keywords recognized by silx and PyMca plot windows may differ.
applyMethod(name)[source]

The plugin is asked to apply the method associated to name.

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 dictionary 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.
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]]

If just_legend is True, it returns a list of the form:

[legend0, legend1, ..., legendn]
getGraphTitle()[source]
Returns:The graph title
Return type:string
getGraphXLabel()[source]
Returns:The graph X axis label
Return type:string
getGraphXLimits()[source]

Get the graph X limits.

Returns:Two floats with the X axis limits
getGraphYLabel()[source]
Returns:The graph Y axis label
Return type:string
getGraphYLimits()[source]

Get the graph Y (left) limits.

Returns:Two floats with the Y (left) axis limits
getMethodPixmap(name)[source]
Parameters:name – The method for which a pixmap is asked
Return type:QPixmap or None
getMethodToolTip(name)[source]

Returns the help associated to the particular method name or None.

Parameters:name – The method for which a tooltip is asked
Return type:string
getMethods(plottype=None)[source]
Parameters:plottype – string or None for the case the plugin only support one type of plots. Implemented values “SCAN”, “MCA” or None
Returns:A list with the NAMES associated to the callable methods that are applicable to the specified type plot. The list can be empty.
Return type:list[string]
getMonotonicCurves()[source]

Convenience method that calls getAllCurves() and makes sure that all of the X values are strictly increasing.

It returns a list of the form:

[[xvalues0, yvalues0, legend0, dict0],
 [xvalues1, yvalues1, legend1, dict1],
 [...],
 [xvaluesn, yvaluesn, legendn, dictn]]
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.

Parameters:
  • legend (string or None) – The legend associated to the curve to be deleted
  • replot (boolean default True) – Flag to indicate plot is to be immediately updated
setActiveCurve(legend)[source]

Funtion to request the plot window to set the curve with the specified legend as the active curve.

Parameters:legend (string) – The legend associated to the curve
setGraphTitle(title)[source]
Parameters:title (string) – The title to be set
setGraphXLabel(title)[source]
Parameters:title (string) – The title to be associated to the X axis
setGraphXLimits(xmin, xmax, replot=False)[source]

Set the graph X limits.

Parameters:
  • xmin (float) – minimum value of the axis
  • xmax (float) – minimum value of the axis
  • replot (boolean default False) – Flag to indicate plot is to be immediately updated
setGraphYLabel(title)[source]
Parameters:title (string) – The title to be associated to the X axis
setGraphYLimits(ymin, ymax, replot=False)[source]

Set the graph Y (left) limits.

Parameters:
  • ymin (float) – minimum value of the axis
  • ymax (float) – minimum value of the axis
  • replot (boolean default False) – Flag to indicate plot is to be immediately updated
PyMca5.PyMcaCore.Plugin1DBase.getPlugin1DInstance(plotWindow, **kw)[source]

This function will be called by the plot window instantiating and calling the plugins. It passes itself as first argument, but the default implementation of the base class only keeps a weak reference to prevent circular references.