geom_imshow()
displays an image specified by 2D or 3D Numpy array.
Whether the image is grayscale or color depends on the shape of the image array:
The array's dtype
can be int, uint or float.
By default, all values in the image array will be transformed to the range [0-255] using a linear scaler.
import numpy as np
from lets_plot import *
LetsPlot.setup_html()
A2x3 = np.array([
[50, 150 ,200],
[200,100,50]
])
ggplot() + geom_imshow(A2x3)
ggplot() + geom_imshow(A2x3, norm=False)
ggplot() + geom_imshow(A2x3, cmap="viridis")
M x N x 3 array
A2x3x3 = np.array([
[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
[[0, 255, 0], [0, 0, 255], [255, 0, 0]]
])
ggplot() + geom_imshow(A2x3x3)
M x N x 4 array
A2x3x4 = np.array([
[[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1]],
[[0, 1, 0, 0.3], [0, 0, 1, 0.3], [1, 0, 0, 0.3]]
])
ggplot() + geom_imshow(A2x3x4)
np.random.seed(42)
image = np.random.choice([0.0, 1.0], [10, 100, 3])
ggplot() + geom_imshow(image) + coord_cartesian()