Plot API for 1D and 2D data.
The Plot implements the plot API initially provided in PyMca.
The Plot uses a dictionary to describe a colormap. This dictionary has the following keys:
Plot.getSupportedColormaps(). At least ‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’ are supported.
‘normalization’: Either ‘linear’ or ‘log’
data, False to use [vmin, vmax]
‘vmin’: float, min value, ignored if autoscale is True
‘vmax’: float, max value, ignored if autoscale is True
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.
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.
‘drawingProgress’ and ‘drawingFinished’ events are sent during drawing interaction (See Plot.setInteractiveMode()).
‘event’: ‘drawingProgress’ or ‘drawingFinished’
It has the following keys: ‘shape’, ‘label’, ‘color’. See Plot.setInteractiveMode().
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.
‘vline’.
coordinates (as in ‘points’).
When the type is ‘rectangle’, the following additional keys are provided:
‘mouseMoved’, ‘mouseClicked’ and ‘mouseDoubleClicked’ events are sent for mouse events.
They provide the following keys:
‘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:
‘markerClicked’ and ‘markerMoving’ events have a ‘xpixel’ and a ‘ypixel’ additional keys, that provide the mouse position in pixels.
‘curveClicked’ and ‘imageClicked’ events are sent when a selectable curve or image is clicked.
Both share the following keys:
‘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.
‘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:
The following events are emitted when the plot is modified. They provide the new state:
A ‘contentChanged’ event is triggered when the content of the plot is updated. It provides the following keys:
‘activeCurveChanged’ and ‘activeImageChanged’ events with the following keys:
‘legend’: Name (str) of the current active item or None if no active item.
active. It is the same as ‘legend’ if ‘updated’ == True
but active item data or style was updated.
‘interactiveModeChanged’ event with a ‘source’ key identifying the object setting the interactive mode.
Bases: object
This class implements the plot API initially provided in PyMca.
Supported backends:
Parameters: |
|
---|
Class attribute setting the default backend for all instances.
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 |
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/update an existing curve, call addCurve() with the existing curve legend.
When curve parameters are not provided, if a curve with the same legend is displayed in the plot, its parameters are used.
Parameters: |
|
---|---|
Returns: | The key string identify this curve |
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: |
|
---|---|
Returns: | The key string identify this image |
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: |
|
---|---|
Returns: | The key string identify this item |
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: |
|
---|---|
Returns: | The key string identify this marker |
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: |
|
---|---|
Returns: | The key string identify this marker |
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: |
|
---|---|
Returns: | The key string identify this marker |
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 |
Show/Hide the curve associated to legend.
Even when hidden, the curve is kept in the list of curves.
Parameters: |
|
---|
Remove one or all element(s) of the given legend and kind.
Examples:
Parameters: |
|
---|
Remove the curve associated to legend from the graph.
Parameters: | legend (str) – The legend associated to the curve to be deleted |
---|
Remove the image associated to legend from the graph.
Parameters: | legend (str) – The legend associated to the image to be deleted |
---|
Remove the item associated to legend from the graph.
Parameters: | legend (str) – The legend associated to the item to be deleted |
---|
Remove the marker associated to legend from the graph.
Parameters: | legend (str) – The legend associated to the marker to be deleted |
---|
Returns the state of the crosshair cursor.
See setGraphCursor().
Returns: | None if the crosshair cursor is not active, else a tuple (color, linewidth, linestyle). |
---|
Toggle the display of a crosshair cursor and set its attributes.
Parameters: |
|
---|
Pan the graph in the given direction by the given factor.
Warning: Pan of right Y axis not implemented!
Parameters: |
|
---|
Enable/Disable active curve selection.
Parameters: | flag (bool) – True (the default) to enable active curve selection. |
---|
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’) |
---|
Return the currently active curve.
It returns None in case of not having an active curve. Default output has the form: [x, y, legend, info, params] where params is a dictionary containing curve parameters.
Warning: Returned values MUST not be modified. Make a copy if you need to modify them.
Parameters: | just_legend (bool) – True to get the legend of the curve, False (the default) to get the curve data and info. |
---|---|
Returns: | legend of the active curve or [x, y, legend, info, params] |
Return type: | str or list |
Make the curve associated to legend the active curve.
Parameters: | legend (str) – The legend associated to the curve or None to have no active curve. |
---|
Returns the currently active image.
It returns None in case of not having an active image.
Default output has the form: [data, legend, info, pixmap, params] where params is a dictionnary containing image parameters.
Warning: Returned values MUST not be modified. Make a copy if you need to modify them.
Parameters: | just_legend (bool) – True to get the legend of the image, False (the default) to get the image data and info. |
---|---|
Returns: | legend of active image or [data, legend, info, pixmap, params] |
Return type: | str or list |
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. |
---|
Returns all curves legend or info and data.
It returns an empty list in case of not having any curve.
Warning: Returned values MUST not be modified. Make a copy if you need to modify them.
Parameters: |
|
---|---|
Returns: | list of legends or list of [x, y, legend, info, params] |
Return type: | list of str or list of list |
Get the data and info of a specific curve.
It returns None in case no matching curve is found.
Warning: Returned values MUST not be modified. Make a copy if you need to modify them.
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 lastest updated curve that is not hidden. is returned if there are curves in the plot. |
---|---|
Returns: | None or list [x, y, legend, parameters] |
Get the data and info of a specific image.
It returns None in case no matching image is found.
Warning: Returned values MUST not be modified. Make a copy if you need to modify them.
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 lastest updated image is returned if there are images in the plot. |
---|---|
Returns: | None or list [image, legend, info, pixmap, params] |
Get the graph X (bottom) limits.
Returns: | Minimum and maximum values of the X axis |
---|
Set the graph X (bottom) limits.
Parameters: |
|
---|
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 |
Set the graph Y limits.
Parameters: |
|
---|
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: |
|
---|
Set the plot main title.
Parameters: | title (str) – Main title of the plot (default: ‘’) |
---|
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’) |
---|
Return the current Y axis label as a str.
Parameters: | axis (str) – The Y axis for which to get the label (left or right) |
---|
Set the plot Y axis label.
The provided label can be temporarily replaced by the Y label of the active curve if any.
Parameters: |
|
---|
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 |
---|
Set the bottom X axis scale (either linear or logarithmic).
Parameters: | flag (bool) – True to use a logarithmic scale, False for linear. |
---|
Set the Y axes scale (either linear or logarithmic).
Parameters: | flag (bool) – True to use a logarithmic scale, False for linear. |
---|
Set the X axis limits adjusting behavior of resetZoom().
Parameters: | flag (bool) – True to resize limits automatically, False to disable it. |
---|
Set the Y axis limits adjusting behavior of resetZoom().
Parameters: | flag (bool) – True to resize limits automatically, False to disable it. |
---|
Set whether the plot keeps data aspect ratio or not.
Parameters: | flag (bool) – True to respect data aspect ratio |
---|
Return the current grid mode, either None, ‘major’ or ‘both’.
See setGraphGrid().
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. |
---|
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. |
---|
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. |
---|
Return the default colormap used by addImage() as a dict.
See Plot for the documentation of the colormap dict.
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. |
---|
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’)
Return the widget the plot is displayed in.
This widget is owned by the backend.
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: |
|
---|
Attach a listener to the backend.
Limitation: Only one listener at a time.
Parameters: | callbackFunction – function accepting a dictionnary as input to handle the graph events If None (default), use a default listener. |
---|
This callback is going 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.
Save a snapshot of the plot.
Supported file formats: “png”, “svg”, “pdf”, “ps”, “eps”, “tif”, “tiff”, “jpeg”, “jpg”.
Parameters: |
|
---|---|
Returns: | False if cannot save the plot, True otherwise |
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. |
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.
Return True if replot is automatically handled, False otherwise.
See :meth`setAutoReplot`.
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. |
---|
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). |
---|
Convert a position in data coordinates to a position in pixels.
Parameters: |
|
---|---|
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. |
Convert a position in pixels to a position in data coordinates.
Parameters: |
|
---|---|
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. |
Plot area bounds in widget coordinates in pixels.
Returns: | bounds as a 4-tuple of int: (left, top, width, height) |
---|
Set the cursor shape.
Parameters: | cursor (str) – Name of the cursor shape |
---|
Handle mouse press event.
Parameters: |
|
---|
Handle mouse move event.
Parameters: |
|
---|
Handle mouse release event.
Parameters: |
|
---|
Handle mouse wheel event.
Parameters: |
|
---|
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().
Switch the interactive mode.
Parameters: |
|
---|
Deprecated, use getInteractiveMode() instead.
Return True if the current interactive state is drawing.
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 simultanelously.
Parameters: |
|
---|
Deprecated, use getInteractiveMode() instead.
Return the draw mode parameters as a dict of None.
It returns None if the interactive moed is not a drawing mode, otherwise, it returns a dict containing the drawing mode parameters as provided to setDrawModeEnabled().
Deprecated, use getInteractiveMode() instead.
Return True if the current interactive state is zooming.
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 simultanelously
Parameters: |
|
---|
Deprecated, use addMarker() instead.
Deprecated, use addXMarker() instead.
Deprecated, use addYMarker() instead.
Deprecated, use isActiveCurveHandling() instead.
Deprecated, use setActiveCurveHandling() instead.
Deprecated, use setYAxisInverted() instead.
Deprecated, use setGraphGrid() instead.
Deprecated, use setKeepDataAspectRatio().