lets_plot.geom_imshow#
- lets_plot.geom_imshow(image_data, cmap=None, *, norm=None, alpha=None, vmin=None, vmax=None, extent=None, compression=None, show_legend=True, color_by='paint_c')#
Display image specified by ndarray with shape.
(M, N) - grey-scale image
(M, N, 3) - color RGB image
(M, N, 4) - color RGB image with alpha channel
This geom is not as flexible as geom_raster() or geom_tile() but vastly superior in the terms of rendering efficiency.
- Parameters:
- image_datandarray
Specify image type, size and pixel values. Supported array shapes are:
(M, N): an image with scalar data. The values are mapped to colors (greys by default) using normalization. See parameters norm, cmap, vmin, vmax.
(M, N, 3): an image with RGB values (0-1 float or 0-255 int).
(M, N, 4): an image with RGBA values (0-1 float or 0-255 int).
The first two dimensions (M, N) define the rows and columns of the image. Out-of-range values are clipped.
- cmapstr, optional
Name of colormap. For example “viridis”, “magma”, “plasma”, “inferno”, or any other colormap which is supported by the Palettable package (jiffyclub/palettable) This parameter is ignored for RGB(A) images.
- normbool, default=True
True - luminance values in grey-scale image will be scaled to [0-255] range using a linear scaler. False - disables scaling of luminance values in grey-scale image. This parameter is ignored for RGB(A) images.
- alpha: float, optional
The alpha blending value, between 0 (transparent) and 1 (opaque).
- vmin, vmaxnumber, optional
Define the data range used for luminance normalization in grey-scale images. This parameter is ignored for RGB(A) images or if parameter norm=False.
- extentlist of 4 numbers: [left, right, bottom, top], optional
Define image’s bounding box in terms of the “data coordinates”.
left, right: coordinates of pixels’ outer edge along the x-axis for pixels in the 1-st and the last column.
bottom, top: coordinates of pixels’ outer edge along the y-axis for pixels in the 1-st and the last row.
The default is: [-0.5, ncol-0.5, -0.5, nrow-0.5]
- compressionint, optional
The compression level to be used by the
zlib
module. Values from 0 (no compression) to 9 (highest). Value None means that the zlib module uses the default level of compression (which is generally acceptable).- show_legendbool, default=True
Greyscale images only. False - do not show legend for this layer.
- color_by{‘fill’, ‘color’, ‘paint_a’, ‘paint_b’, ‘paint_c’}, default=’paint_c’
Define the color aesthetic used by the legend shown for a greyscale image.
- Returns:
- LayerSpec
Geom object specification.
Notes
This geom doesn’t understand any aesthetics. It doesn’t support color scales either.
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_imshow(image)
1import numpy as np 2from lets_plot import * 3LetsPlot.setup_html() 4n = 64 5image = 256 * np.linspace(np.linspace(0, .5, n), \ 6 np.linspace(.5, .5, n), n) 7ggplot() + geom_imshow(image, norm=False)
1import numpy as np 2from lets_plot import * 3LetsPlot.setup_html() 4np.random.seed(42) 5image = np.random.normal(size=(64, 64)) 6ggplot() + geom_imshow(image, vmin=-1, vmax=1)