Plotting Utilities

This module contains a series of utilities for creating two dimensional plots that are useful for generating documentation and vignettes. We suggest that users leverage starfish.display() for their plotting needs, as the interactive viewer is better able to handle the array of features that starfish needs.

from starfish.util import plot
starfish.util.plot.diagnose_registration(imagestack: ImageStack, *sels: Optional[Mapping[Axes, Union[int, tuple]]], ax=None, title: Optional[str] = None, **kwargs)[source]

Overlays 2-d images extracted from ImageStack for the purpose of visualizing alignment of images from different rounds or channels selected with the sel parameter. Up to six images can be selected and shown in different colors. The same Axes.X and Axes.Y indices should be used for every Selector.

Parameters:
imagestackImageStack

imagestack from which to extract 2-d images for plotting

*selsOptional[Mapping[Axes, Union[int, tuple]]]

Optional, but only if image_stack is already of shape (1, 1, 1, y, x). Selectors to pass ImageStack.sel, Selects the (y, x) planes to be plotted.

ax

Axes to plot on. If not passed, defaults to the current axes.

titleOptional[str]

Title to assign the Axes being plotted on.

kwargs

additional keyword arguments to pass to imshow_plane

starfish.util.plot.image(img: ndarray, cmap: str = 'gray', bar: bool = False, nans: bool = True, clim: Optional[tuple] = None, size: int = 7, ax=None)[source]

Display an image using matplotlib.

This function provides a simple interface for displaying images with optional colorbar, NaN handling, and color scaling. It is designed to replace the showit.image function.

Parameters:
imgnp.ndarray

The image to display. Can be 2D (grayscale) or 3D (RGB).

cmapstr, optional

Colormap to use for grayscale images. Default is ‘gray’.

barbool, optional

Whether to append a colorbar. Default is False.

nansbool, optional

Whether to replace NaNs with 0s. Default is True.

climtuple, optional

Limits for scaling image as (vmin, vmax). Default is None.

sizeint, optional

Size of the figure if ax is not provided. Default is 7.

axmatplotlib axis, optional

An existing axis to plot into. If None, creates a new figure.

Returns:
immatplotlib.image.AxesImage

The image object created by imshow.

starfish.util.plot.imshow_plane(image_stack: ImageStack, sel: Optional[Mapping[Axes, Union[int, tuple]]] = None, ax=None, title: Optional[str] = None, **kwargs) None[source]

Plot a single plane of an ImageStack. If passed a selection function (sel), the stack will be subset using ImageStack.sel(). If ax is passed, the function will be plotted in the provided axis. Additional kwargs are passed to plt.imshow()

Parameters:
image_stackImageStack

imagestack from which to extract a 2-d image for plotting

selOptional[Mapping[Axes, Union[int, tuple]]]

Optional, but only if image_stack is already of shape (1, 1, 1, y, x). Selector to pass ImageStack.sel, Selects the (y, x) plane to be plotted.

ax

Axes to plot on. If not passed, defaults to the current axes.

titleOptional[str]

Title to assign the Axes being plotted on.

kwargs

additional keyword arguments to pass to plt.imshow

starfish.util.plot.intensity_histogram(image_stack: ImageStack, sel: Optional[Mapping[Axes, Union[int, tuple]]] = None, ax=None, title: Optional[str] = None, **kwargs) None[source]

Plot the 1-d intensity histogram of linearized image_stack.

Parameters:
image_stackImageStack

imagestack containing intensities

selOptional[Mapping[Axes, Union[int, tuple]]]

Optional, Selector to pass ImageStack.sel that will restrict the histogram construction to the specified subset of image_stack.

ax

Axes to plot on. If not passed, defaults to the current axes.

titleOptional[str]

Title to assign the Axes being plotted on.

kwargs

additional keyword arguments to pass to plt.hist

starfish.util.plot.overlay_spot_calls(image_stack: ImageStack, intensities: IntensityTable, sel: Optional[Mapping[Axes, Union[int, tuple]]] = None, ax=None, title: Optional[str] = None, imshow_kwargs: Optional[Mapping[str, Any]] = None, scatter_kwargs: Optional[Mapping[str, Any]] = None) None[source]

Overlays spot calls atop a 2-d image extracted from ImageStack. Manages sub-selection from the IntensityTable and ImageStack based on provided sel parameter.

Parameters:
image_stackImageStack

imagestack from which to extract a 2-d image for plotting

intensitiesIntensityTable

contains spots to overlay on ImageStack.

selOptional[Mapping[Axes, Union[int, tuple]]]

Optional, but only if image_stack is already of shape (1, 1, 1, y, x). Selector to pass ImageStack.sel, Selects the (y, x) plane to be plotted. Will also be used to reduce the spots from intensities.

ax

Axes to plot on. If not passed, defaults to the current axes.

titleOptional[str]

Title to assign the Axes being plotted on.

imshow_kwargsOptional[Mapping[str, Any]]

additional keyword arguments to pass to imshow

scatter_kwargsOptional[Mapping[str, Any]]

additional keyword arguments to pass to scatter