lets_plot.geom_image

lets_plot.geom_image(image_data, norm=None, vmin=None, vmax=None)

Displays image specified by ndarray with shape (n, m) or (n, m, 3) or (n, m, 4). This geom is not as flexible as geom_raster() or geom_tile() but vastly superior in the terms of rendering efficiency.

Parameters
image_datandarray

Specifies image type, size and pixel values in numpy.ndarray.

normbool, default=True

False - disables default scaling of a 2-D float (luminance) input to the (0, 1) range.

vminfloat, default=None

Uses normalized luminance data. Only applied to gray-scale images encoded as float array.

vmaxfloat, default=None

Uses normalized luminance data. Only applied to gray-scale images encoded as float array.

Returns
LayerSpec

Geom object specification.

Notes

This geom doesn’t understand any aesthetics. It doesn’t support color scales either.

The following images will be rendered depending on the input array:

  • n x m - gray-scale,

  • n x m x 3 - RGB,

  • n x m x 4 - RGBA.

The type of values in array can be int, uint or float of any size. The value for each component of integer arrays should be in the range [0, 255]. The value for each component of float arrays should be in the range [0, 1] for RGB or RGBA images.

If gray-scale is encoded as float array then the values will be normalized. If arguments vmin/vmax are specified, they will be used in normalization. Otherwise, min/max value will be computed from the image data.

Examples

1import numpy as np
2from lets_plot import *
3LetsPlot.setup_html()
4np.random.seed(42)
5image = np.random.randint(256, size=(64, 64, 4))
6ggplot() + geom_image(image)