Skip to main content
`Ctrl`+`K`

# `PlotWindow`: Plot widget with toolbar

A `PlotWidget` with additional toolbars.

The `PlotWindow` is a subclass of `PlotWidget`.

## `PlotWindow` class

class PlotWindow(parent=None, backend=None, resetzoom=True, autoScale=True, logScale=True, grid=True, curveStyle=True, colormap=True, aspectRatio=True, yInverted=True, copy=True, save=True, print_=True, control=False, position=False, roi=True, mask=True, fit=False)

  Bases: `PlotWidget`

  Qt Widget providing a 1D/2D plot area and additional tools.

  This widgets inherits from `PlotWidget` and provides its plot API.

  Initialiser parameters:

  Parameters:

    - parent – The parent of this widget or None.

    - backend (str or `BackendBase.BackendBase`) – The backend to use for the plot (default: matplotlib). See `PlotWidget` for the list of supported backend.

    - resetzoom (bool) – Toggle visibility of reset zoom action.

    - autoScale (bool) – Toggle visibility of axes autoscale actions.

    - logScale (bool) – Toggle visibility of axes log scale actions.

    - grid (bool) – Toggle visibility of grid mode action.

    - curveStyle (bool) – Toggle visibility of curve style action.

    - colormap (bool) – Toggle visibility of colormap action.

    - aspectRatio (bool) – Toggle visibility of aspect ratio button.

    - yInverted (bool) – Toggle visibility of Y axis direction button.

    - copy (bool) – Toggle visibility of copy action.

    - save (bool) – Toggle visibility of save action.

    - print (bool) – Toggle visibility of print action.

    - control (bool) – True to display an Options button with a sub-menu to show legends, toggle crosshair and pan with arrows. (Default: False)

    - position – True to display widget with (x, y) mouse position (Default: False). It also supports a list of (name, funct(x, y)->value) to customize the displayed values. See `PositionInfo`.

    - roi (bool) – Toggle visibilty of ROI action.

    - mask (bool) – Toggle visibilty of mask action.

    - fit (bool) – Toggle visibilty of fit action.

  setBackend(backend)

    Set the backend to use for rendering.

    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:

      backend (Union[str,BackendBase,List[Union[str,BackendBase]]]) – The backend to use, in: ‘matplotlib’ (default), ‘mpl’, ‘opengl’, ‘gl’, ‘none’, a `BackendBase.BackendBase` class. If multiple backends are provided, the first available one is used.

    Raises:

      - ValueError – Unsupported backend descriptor

      - RuntimeError – Error while loading a backend

  setBackgroundColor(color)

    Set the background color of this widget.

    Parameters:

      color (Union[List[int],List[float],QColor]) – The new RGB(A) color.

  setDataBackgroundColor(color)

    Set the background color of the plot area.

    Set to None or an invalid QColor to use the background color.

    Parameters:

      color (Union[List[int],List[float],QColor,None]) – The new RGB(A) color.

  setForegroundColor(color)

    Set the foreground color of this widget.

    Parameters:

      color (Union[List[int],List[float],QColor]) – The new RGB(A) color.

  getInteractiveModeToolBar()

    Returns QToolBar controlling interactive mode.

    Return type:

      QToolBar

  getOutputToolBar()

    Returns QToolBar containing save, copy and print actions

    Return type:

      QToolBar

  getPositionInfoWidget()

    Returns the widget displaying current cursor position information

    Return type:

      PositionInfo

  getSelectionMask()

    Return the current mask handled by `maskToolsDockWidget`.

    Returns:

      The array of the mask with dimension of the ‘active’ image. If there is no active image, an empty array is returned.

    Return type:

      2D numpy.ndarray of uint8

  setSelectionMask(mask)

    Set the mask handled by `maskToolsDockWidget`.

    If the provided mask has not the same dimension as the ‘active’ image, it will by cropped or padded.

    Parameters:

      mask (numpy.ndarray of uint8 of dimension 2, C-contiguous. Array of other types are converted.) – The array to use for the mask.

    Returns:

      True if success, False if failed

  toolBar()

    Return a QToolBar from the QAction of the PlotWindow.

  menu(title='Plot', parent=None)

    Return a QMenu from the QAction of the PlotWindow.

    Parameters:

      - title (str) – The title of the QMenu

      - parent – See `QMenu`

  addTabbedDockWidget(dock_widget)

    Add a dock widget as a new tab if there are already dock widgets in the plot. When the first tab is added, the area is chosen depending on the plot geometry: if the window is much wider than it is high, the right dock area is used, else the bottom dock area is used.

    Parameters:

      dock_widget – Instance of `QDockWidget` to be added.

  removeDockWidget(dockwidget)

    Removes the dockwidget from the main window layout and hides it.

    Note that the dockwidget is not deleted.

    Parameters:

      dockwidget (QDockWidget)

  getColorBarWidget()

    Returns the embedded `ColorBarWidget` widget.

    Return type:

      ColorBarWidget

  getLegendsDockWidget()

    DockWidget with Legend panel

  getCurvesRoiWidget()

    Return the `CurvesROIWidget`.

    `silx.gui.plot.CurvesROIWidget.CurvesROIWidget` offers a getter and a setter for the ROI data:

    > - `CurvesROIWidget.getRois()`

    > - `CurvesROIWidget.setRois()`

  getMaskToolsDockWidget()

    DockWidget with image mask panel (lazy-loaded).

  getStatsWidget()

    Returns a BasicStatsWidget connected to this plot

    Return type:

      BasicStatsWidget

  getConsoleAction()

    QAction handling the IPython console activation.

    By default, it is connected to a method that initializes the console widget the first time the user clicks the “Console” menu button. The following clicks, after initialization is done, will toggle the visibility of the console widget.

    Return type:

      QAction

  getCrosshairAction()

    Action toggling crosshair cursor mode.

    Return type:

      actions.PlotAction

  getMaskAction()

    QAction toggling image mask dock widget

    Return type:

      QAction

  getPanWithArrowKeysAction()

    Action toggling pan with arrow keys.

    Return type:

      actions.PlotAction

  getRoiAction()

    QAction toggling curve ROI dock widget

    Return type:

      QAction

  getResetZoomAction()

    Action resetting the zoom

    Return type:

      actions.PlotAction

  getZoomInAction()

    Action to zoom in

    Return type:

      actions.PlotAction

  getZoomOutAction()

    Action to zoom out

    Return type:

      actions.PlotAction

  getXAxisAutoScaleAction()

    Action to toggle the X axis autoscale on zoom reset

    Return type:

      actions.PlotAction

  getYAxisAutoScaleAction()

    Action to toggle the Y axis autoscale on zoom reset

    Return type:

      actions.PlotAction

  getXAxisLogarithmicAction()

    Action to toggle logarithmic X axis

    Return type:

      actions.PlotAction

  getYAxisLogarithmicAction()

    Action to toggle logarithmic Y axis

    Return type:

      actions.PlotAction

  getGridAction()

    Action to toggle the grid visibility in the plot

    Return type:

      actions.PlotAction

  getCurveStyleAction()

    Action to change curve line and markers styles

    Return type:

      actions.PlotAction

  getColormapAction()

    Action open a colormap dialog to change active image and default colormap.

    Return type:

      actions.PlotAction

  getKeepDataAspectRatioButton()

    Button to toggle aspect ratio preservation

    Return type:

      PlotToolButtons.AspectToolButton

  getKeepDataAspectRatioAction()

    Action associated to keepDataAspectRatioButton. Use this to change the visibility of keepDataAspectRatioButton in the toolbar (See `QToolBar.addWidget()` documentation).

    Return type:

      actions.PlotAction

  getYAxisInvertedButton()

    Button to switch the Y axis orientation

    Return type:

      PlotToolButtons.YAxisOriginToolButton

  getYAxisInvertedAction()

    Action associated to yAxisInvertedButton. Use this to change the visibility yAxisInvertedButton in the toolbar. (See `QToolBar.addWidget()` documentation).

    Return type:

      actions.PlotAction

  getIntensityHistogramAction()

    Action toggling the histogram intensity Plot widget

    Return type:

      actions.PlotAction

  getCopyAction()

    Action to copy plot snapshot to clipboard

    Return type:

      actions.PlotAction

  getSaveAction()

    Action to save plot

    Return type:

      actions.PlotAction

  getPrintAction()

    Action to print plot

    Return type:

      actions.PlotAction

  getFitAction()

    Action to fit selected curve

    Return type:

      actions.PlotAction

  getMedianFilter1DAction()

    Action toggling the 1D median filter

    Return type:

      actions.PlotAction

  getMedianFilter2DAction()

    Action toggling the 2D median filter

    Return type:

      actions.PlotAction

  getColorBarAction()

    Action toggling the colorbar show/hide action

    Warning

    to show/hide the plot colorbar call directly the ColorBar widget using getColorBarWidget()

    Return type:

      actions.PlotAction

## `Plot1D`: Plot curves

class Plot1D(parent=None, backend=None)

  Bases: `PlotWindow`

  PlotWindow with tools specific for curves.

  This widgets provides the plot API of `PlotWidget`.

  Parameters:

    - parent – The parent of this widget

    - backend (str or `BackendBase.BackendBase`) – The backend to use for the plot (default: matplotlib). See `PlotWidget` for the list of supported backend.

## `Plot2D`: Plot images

class Plot2D(parent=None, backend=None)

  Bases: `PlotWindow`

  PlotWindow with a toolbar specific for images.

  This widgets provides the plot API of :~:.PlotWidget.

  Parameters:

    - parent – The parent of this widget

    - backend (str or `BackendBase.BackendBase`) – The backend to use for the plot (default: matplotlib). See `PlotWidget` for the list of supported backend.

  getProfileToolbar()

    Profile tools attached to this plot

    See `silx.gui.plot.Profile.ProfileToolBar`

  getProfilePlot()

    Return plot window used to display profile curve.

    Returns:

      `Plot1D`