seaborn_image.imshow#

seaborn_image.imshow(data, **kwargs)#

Plot data as a 2-D image with options to ignore outliers, add scalebar, colorbar, title.

Parameters:
  • data (array-like) – Image data. Supported array shapes are all matplotlib.pyplot.imshow array shapes

  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot image on. If None, figure and axes are auto-generated, by default None

  • cmap (str or matplotlib.colors.Colormap, optional) – Colormap for image. Can be a seaborn-image colormap or default matplotlib colormaps or any other colormap converted to a matplotlib colormap, by default None

  • gray (bool, optional) – If True and data is RGB image, it will be converted to grayscale. If True and cmap is None, cmap will be set to “gray”, by default None

  • vmin (float, optional) – Minimum data value that colormap covers, by default None

  • vmax (float, optional) – Maximum data value that colormap covers, by default None

  • alpha (float or array-like, optional) – matplotlib.pyplot.imshow alpha blending value from 0 (transparent) to 1 (opaque), by default None

  • origin (str, optional) – Image origin, by default None

  • interpolation (str, optional) – matplotlib.pyplot.imshow interpolation method used, by default None

  • norm (matplotlib.colors.Normalize, optional) – matplotlib Normalize instance used to scale scalar data before mapping to colors using cmap

  • robust (bool, optional) – If True and vmin or vmax are None, colormap range is calculated based on the percentiles defined in perc parameter, by default False

  • perc (tuple or list, optional) – If robust is True, colormap range is calculated based on the percentiles specified instead of the extremes, by default (2, 98) - 2nd and 98th percentiles for min and max values

  • dx (float, optional) – Size per pixel of the image data. Specifying dx and units adds a scalebar to the image, by default None

  • units (str, optional) – Units of dx, by default None

  • dimension (str, optional) –

    dimension of dx and units, by default None Options include (similar to matplotlib_scalebar):

    • ”si” : scale bar showing km, m, cm, etc.

    • ”imperial” : scale bar showing in, ft, yd, mi, etc.

    • ”si-reciprocal” : scale bar showing 1/m, 1/cm, etc.

    • ”angle” : scale bar showing °, ʹ (minute of arc) or ʹʹ (second of arc)

    • ”pixel” : scale bar showing px, kpx, Mpx, etc.

  • describe (bool, optional) – Brief statistical description of the data, by default False

  • map_func (callable, optional) – Transform input image data using this function. All function arguments must be passed as kwargs.

  • cbar (bool, optional) – Specify if a colorbar is to be added to the image, by default True. If data is RGB image, cbar is False

  • orientation (str, optional) –

    Specify the orientaion of colorbar, by default “v”. Options include :

    • ’h’ or ‘horizontal’ for a horizontal colorbar to the bottom of the image.

    • ’v’ or ‘vertical’ for a vertical colorbar to the right of the image.

  • cbar_log (bool, optional) – Log scale colormap and colorbar

  • cbar_label (str, optional) – Colorbar label, by default None

  • cbar_ticks (list, optional) – List of colorbar ticks, by default None

  • showticks (bool, optional) – Show image x-y axis ticks, by default False

  • despine (bool, optional) – Remove axes spines from image axes as well as colorbar axes, by default None

Returns:

Matplotlib axes where the image is drawn.

Return type:

matplotlib.axes.Axes

Raises:
  • TypeError – if cmap is not str or matplotlib.colors.Colormap

  • TypeError – if ax is not matplotlib.axes.Axes

  • TypeError – if describe is not bool

  • TypeError – if robust is not bool

  • TypeError – if cbar is not bool

  • TypeError – if orientation is not str

  • TypeError – if cbar_label is not str

  • TypeError – if showticks is not bool

  • TypeError – if despine is not bool

  • AssertionError – if len(perc) is not equal to 2

  • AssertionError – if the first element of perc is greater than the second

Examples

Plot image

>>> import seaborn_image as isns
>>> img = isns.load_image("polymer")
>>> isns.imgplot(img)
../_images/imshow-1.png

Get image statistics

>>> isns.imgplot(img, describe=True)
../_images/imshow-2.png

Add a scalebar

>>> isns.imgplot(img, dx=15, units="nm")
../_images/imshow-3.png

Change colormap

>>> isns.imgplot(img, cmap="deep")
../_images/imshow-4.png

Rescale colormap to exclude outliers while plotting

Image with outliers

>>> img_out = isns.load_image("polymer outliers")
>>> isns.imgplot(img_out)
../_images/imshow-5.png

Rescale colormap using robust parameter

>>> isns.imgplot(img_out, robust=True)
../_images/imshow-6.png

Change percentile for robust parameter

>>> isns.imgplot(img_out, robust=True, perc=(0.5,99.5))
../_images/imshow-7.png

Map a function to transform input image

>>> from skimage.exposure import adjust_gamma
>>> cells = isns.load_image("cells")[:, :, 32]
>>> isns.imgplot(cells, map_func=adjust_gamma, gamma=0.5)
../_images/imshow-8.png

Convert RGB image to grayscale

>>> from skimage.data import astronaut
>>> isns.imgplot(astronaut(), gray=True)
../_images/imshow-9.png

Change colorbar orientation

>>> isns.imgplot(img, orientation="h") # horizontal
../_images/imshow-10.png
>>> isns.imgplot(img, orientation="v") # vertical
../_images/imshow-11.png

Add colorbar label

>>> isns.imgplot(img, cbar_label="Height (nm)")
../_images/imshow-12.png

Despine image and colorbar

>>> isns.imgplot(img, despine=True)
../_images/imshow-13.png

Change colorbar and colormap to log scale

>>> pl = isns.load_image("fluorescence")
>>> isns.imgplot(pl, cbar_log=True)
../_images/imshow-14.png

Change image transparency

>>> isns.imgplot(pl, alpha=0.75)
../_images/imshow-15.png