StackView: Plot a stack of images

QWidget displaying a 3D volume as a stack of 2D images.

The StackView class implements this widget.

Basic usage of StackView is through the following methods:

The StackView uses PlotWindow and also exposes a subset of the silx.gui.plot.Plot API for further control (plot title, axes labels, ...).

The StackViewMainWindow class implements a widget that adds a status bar displaying the 3D index and the value under the mouse cursor.

Example:

import numpy
import sys
from silx.gui import qt
from silx.gui.plot.StackView import StackViewMainWindow


app = qt.QApplication(sys.argv[1:])

# synthetic data, stack of 100 images of size 200x300
mystack = numpy.fromfunction(
    lambda i, j, k: numpy.sin(i/15.) + numpy.cos(j/4.) + 2 * numpy.sin(k/6.),
    (100, 200, 300)
)


sv = StackViewMainWindow()
sv.setColormap("jet", autoscale=True)
sv.setStack(mystack)
sv.setLabels(["1st dim (0-99)", "2nd dim (0-199)",
              "3rd dim (0-299)"])
sv.show()

app.exec_()

StackView class

class silx.gui.plot.StackView.StackView(parent=None, resetzoom=True, backend=None, autoScale=False, logScale=False, grid=False, colormap=True, aspectRatio=True, yinverted=True, copy=True, save=True, print_=True, control=False, position=None, mask=True)[source]

Stack view widget, to display and browse through stack of images.

The profile tool can be switched to “3D” mode, to compute the profile on each image of the stack (not only the active image currently displayed) and display the result as a slice.

Parameters:
  • parent (QWidget) – the Qt parent, or None
  • backend (str or BackendBase.BackendBase) – The backend to use for the plot. The default is to use matplotlib.
  • 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.
  • 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 silx.gui.plot.PlotTools.PositionInfo.
  • mask (bool) – Toggle visibilty of mask action.
valueChanged

Signals that the data value under the cursor has changed.

It provides: row, column, data value.

sigPlaneSelectionChanged

Signal emitted when there is a change is perspective/displayed axes.

It provides the perspective as an integer, with the following meaning:

  • 0: axis Y is the 2nd dimension, axis X is the 3rd dimension
  • 1: axis Y is the 1st dimension, axis X is the 3rd dimension
  • 2: axis Y is the 1st dimension, axis X is the 2nd dimension
sigStackChanged

Signal emitted when the stack is changed. This happens when a new volume is loaded, or when the current volume is transposed (change in perspective).

The signal provides the size (number of pixels) of the stack. This will be 0 if the stack is cleared, else it will be a positive integer.

setOptionVisible(isVisible)[source]

Set the visibility of the browsing options.

Parameters:isVisible (bool) – True to have the options visible, else False
setFrameNumber(number)[source]

Set the frame selection to a specific value :param int number: Number of the frame

setStack(stack, perspective=0, reset=True)[source]

Set the 3D stack.

The perspective parameter is used to define which dimension of the 3D array is to be used as frame index. The lowest remaining dimension number is the row index of the displayed image (Y axis), and the highest remaining dimension is the column index (X axis).

Parameters:
  • stack (3D numpy.ndarray, or 3D h5py.Dataset, or list/tuple of 2D numpy arrays, or None.) – 3D stack, or None to clear plot.
  • perspective (int) – Dimension for the frame index: 0, 1 or 2. By default, the dimension for the image index is the first dimension of the 3D stack (perspective=0).
  • reset (bool) – Whether to reset zoom or not.
getStack(copy=True, returnNumpyArray=False)[source]

Get the original stack, as a 3D array or dataset.

The output has the form: [data, params] where params is a dictionary containing display parameters.

Parameters:
  • copy (bool) – If True (default), then the object is copied and returned as a numpy array. Else, a reference to original data is returned, if possible. If the original data is not a numpy array and parameter returnNumpyArray is True, a copy will be made anyway.
  • returnNumpyArray (bool) – If True, the returned object is guaranteed to be a numpy array.
Returns:

3D stack and parameters.

Return type:

(numpy.ndarray, dict)

getCurrentView(copy=True, returnNumpyArray=False)[source]

Get the stack, as it is currently displayed.

The first index of the returned stack is always the frame index. If the perspective has been changed in the widget since the data was first loaded, this will be reflected in the order of the dimensions of the returned object.

The output has the form: [data, params] where params is a dictionary containing display parameters.

Parameters:
  • copy (bool) – If True (default), then the object is copied and returned as a numpy array. Else, a reference to original data is returned, if possible. If the original data is not a numpy array and parameter returnNumpyArray is True, a copy will be made anyway.
  • returnNumpyArray (bool) – If True, the returned object is guaranteed to be a numpy array.
Returns:

3D stack and parameters.

Return type:

(numpy.ndarray, dict)

getActiveImage(just_legend=False)[source]

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 dictionary containing image parameters.

Parameters:just_legend (bool) – True to get the legend of the image, False (the default) to get the image data and info. Note: StackView uses the same legend for all frames.
Returns:legend or [data, legend, info, pixmap, params]
Return type:str or list
clear()[source]

Clear the widget:

  • clear the plot
  • clear the loaded data volume
resetZoom()[source]

Reset the plot limits to the bounds of the data and redraw the plot.

getGraphTitle()[source]

Return the plot main title as a str.

setGraphTitle(title='')[source]

Set the plot main title.

Parameters:title (str) – Main title of the plot (default: ‘’)
setLabels(labels=None)[source]

Set the labels to be displayed on the plot axes.

You must provide a sequence of 3 strings, corresponding to the 3 dimensions of the original data volume. The proper label will automatically be selected for each plot axis when the volume is rotated (when different axes are selected as the X and Y axes).

Parameters:labels (list(str)) – 3 labels corresponding to the 3 dimensions of the data volumes.
getGraphXLabel()[source]

Return the current horizontal axis label as a str.

setGraphXLabel(label=None)[source]

Set the plot horizontal axis label.

Parameters:label (str) – The horizontal axis label
getGraphYLabel(axis='left')[source]

Return the current vertical axis label as a str.

Parameters:axis (str) – The Y axis for which to get the label (left or right)
setGraphYLabel(label=None, axis='left')[source]

Set the vertical axis label on the plot.

Parameters:
  • label (str) – The Y axis label
  • axis (str) – The Y axis for which to set the label (left or right)
setYAxisInverted(flag=True)[source]

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
isYAxisInverted()[source]

Return True if Y axis goes from top to bottom, False otherwise.

getSupportedColormaps()[source]

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

getColormap()[source]

Get the current colormap description.

Returns:A description of the current colormap. See setColormap() for details.
Return type:dict
setColormap(colormap=None, normalization=None, autoscale=None, vmin=None, vmax=None, colors=None)[source]

Set the colormap and update active image.

Parameters that are not provided are taken from the current colormap.

The colormap parameter can also be a dict with the following keys:

  • name: string. The colormap to use: ‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’.

  • normalization: string. The mapping to use for the colormap: either ‘linear’ or ‘log’.

  • autoscale: bool. Whether to use autoscale (True) or range provided by keys ‘vmin’ and ‘vmax’ (False).

  • vmin: float. The minimum value of the range to use if ‘autoscale’ is False.

  • vmax: float. The maximum value of the range to use if ‘autoscale’ is False.

  • colors: optional. Nx3 or Nx4 array of float in [0, 1] or uint8.

    List of RGB or RGBA colors to use (only if name is None)

Parameters:
  • colormap (dict or str.) – Name of the colormap in ‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’. Or the description of the colormap as a dict.
  • normalization (str) – Colormap mapping: ‘linear’ or ‘log’.
  • autoscale (bool) – Whether to use autoscale or [vmin, vmax] range. Default value of autoscale is True if data is a numpy array, False if data is a h5py dataset.
  • vmin (float) – The minimum value of the range to use if ‘autoscale’ is False.
  • vmax (float) – The maximum value of the range to use if ‘autoscale’ is False.
  • colors (numpy.ndarray) – Only used if name is None. Custom colormap colors as Nx3 or Nx4 RGB or RGBA arrays
isKeepDataAspectRatio()[source]

Returns whether the plot is keeping data aspect ratio or not.

setKeepDataAspectRatio(flag=True)[source]

Set whether the plot keeps data aspect ratio or not.

Parameters:flag (bool) – True to respect data aspect ratio
getProfileToolbar()[source]

Profile tools attached to this plot

See silx.gui.plot.Profile.Profile3DToolBar

getProfileWindow1D()[source]

Plot window used to display 1D profile curve.

Returns:Plot1D
getProfileWindow2D()[source]

Plot window used to display 2D profile image.

Returns:Plot2D

StackViewMainWindow class

class silx.gui.plot.StackView.StackViewMainWindow(parent=None)[source]

Bases: silx.gui.plot.StackView.StackView

This class is a StackView with a menu, an additional toolbar to set the plot limits, and a status bar to display the value and 3D index of the data samples hovered by the mouse cursor.

Parameters:parent (QWidget) – Parent widget, or None
setStack(stack, *args, **kwargs)[source]

Set the displayed stack.

See StackView.setStack() for details.

Table Of Contents

Previous topic

ImageView: Plot an image with side histograms

Next topic

Plot: Full plot API

This Page