The PlotWidget is a Qt widget providing the plot API initially provided in PyMca. It is the basis of other plot widget, thus all plot widgets share the same API.
For an introduction and examples of the plot API, see Getting started with plot widgets.
Bases: PyQt4.QtGui.QMainWindow
Qt Widget providing a 1D/2D plot.
This widget is a QMainWindow. This class implements the plot API initially provided in PyMca.
Supported backends:
Parameters: |
|
---|
Those methods allow to add and update plotted data:
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: |
|
---|---|
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 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: |
|
---|---|
Returns: | The key string identify this scatter |
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: |
|
---|---|
Returns: | The key string identify this histogram |
Those methods return objects providing access to plotted data:
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 |
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 |
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 |
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 |
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: |
|
---|---|
Returns: | list of curves’ legend or items.Curve |
Return type: | list of str or list of items.Curve |
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 |
It is also possible to add point or line markers to the plot:
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 |
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 |
Remove one or all element(s) of the given legend and kind.
Examples:
Parameters: |
|
---|
Those methods handle the plot title:
Those two methods give access to items.Axis which handle the limits, scales and labels of axis:
Returns the X axis
New in version 0.6.
Return type: | items.Axis |
---|
Returns an Y axis
New in version 0.6.
Parameters: | axis (str) – The Y axis to return (‘left’ or ‘right’). |
---|---|
Return type: | items.Axis |
The following methods handle plot limits, aspect ratio, grid and axes display:
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: |
|
---|
Returns whether the plot is keeping data aspect ratio or not.
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().
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 getXAxis(), getYAxis() and Axis.setAutoScale()). It keeps current limits on axes that are not in autoscale mode.
Extra margins can be added around the data inside the plot area (see setDataMargins()). 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). |
---|
The following methods allow to add margins around the data when performing a zoom reset:
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.
Those methods set-up default values for PlotWidget.addCurve() and PlotWidget.addImage():
Return the default Colormap used by addImage().
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 (Colormap) – The description of the default colormap, or None to set the Colormap to a linear autoscale gray colormap. |
---|
Get the supported colormap names as a tuple of str.
The list contains at least: (‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’, ‘magma’, ‘inferno’, ‘plasma’, ‘viridis’)
Those methods allow to change the interaction mode (e.g., drawing mode) of the plot and to toggle the use of a crosshair cursor:
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: |
|
---|
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: |
|
---|
Returns this PlotWidget’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 |
Plot area bounds in widget coordinates in pixels.
Returns: | bounds as a 4-tuple of int: (left, top, width, height) |
---|
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. |
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.
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 |
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. |
---|
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 |
Return the widget the plot is displayed in.
This widget is owned by the backend.
Save a snapshot of the plot.
Supported file formats depends on the backend in use. The following file formats are always supported: “png”, “svg”. The matplotlib backend supports more formats: “pdf”, “ps”, “eps”, “tiff”, “jpeg”, “jpg”.
Parameters: |
|
---|---|
Returns: | False if cannot save the plot, True otherwise |
The PlotWidget provides the following Qt signals:
Signal for all events of the plot.
The signal information is provided as a dict. See PlotWidget for documentation of the content of the dict.
Signal emitted when plot keep aspect ratio has changed
Signal emitted when plot grid has changed
Signal emitted when plot crosshair cursor has changed
Signal emitted when pan with arrow keys has changed
Signal emitted when the content of the plot is changed.
It provides the following information:
Signal emitted when the active curve has changed.
It provides the following information:
Signal emitted when the active image has changed.
It provides the following information:
Signal emitted when the active Scatter has changed.
It provides the following information:
Signal emitted when the interactive mode has changed
It provides the source as passed to setInteractiveMode().