Display multichannel arrays
Render RGB or RGBA pixel arrays interactively in a Plotly figure.
Plotly · Class
go.Image displays multichannel image data as a Plotly graph-object trace. Provide raw pixel values with z or a base64-encoded image through source.
go.Image is a low-level graph-object trace for displaying multichannel image data. Supply pixel values through z, or use source with a base64-encoded image to reduce browser payload and serialization work.
go.Image(z=None, source=None, zmin=None, zmax=None, **kwargs)| Name | Type | Description |
|---|---|---|
z | array or list of numerical values | Image pixel data as an array or list of numerical values; intended for multichannel images. |
source | base64 binary string | A base64-encoded binary image string. |
zmin | array-like | Lower data bound used for color mapping; for go.Image, provide one value per channel. |
zmax | array-like | Upper data bound used for color mapping; for go.Image, provide one value per channel. |
A Plotly graph-object image trace.
plotly.graph_objects.go.Image when you need direct trace-level control over an image.source for a base64-encoded image payload instead of passing raw pixel arrays.go.Heatmap for single-channel images; this trace requires multiple channels.go.layout.Image, which is intended for background images and logos.zmin or zmax, provide values for every channel rather than relying on a single scalar.import plotly.graph_objects as go
img_rgb = [
[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
[[0, 255, 0], [0, 0, 255], [255, 0, 0]],
]
fig = go.Figure(go.Image(z=img_rgb))
fig.show()Creates and displays a Plotly figure from a small RGB pixel array.
Render RGB or RGBA pixel arrays interactively in a Plotly figure.
Send compressed PNG or JPEG data instead of large raw arrays.
Control how channel values map to displayed colors.
go.Image used for?go.Image is a graph-object trace for displaying multichannel image data. A typical figure passes an RGB array to z and then renders the figure.
Follow-up: How would you display a grayscale image? Use go.Heatmap, because go.Image accepts only multichannel images.
The z property accepts an array or list of numerical values representing image data. The alternative source property accepts a base64 binary string.
Follow-up: Why might source be preferable? PNG or JPEG compression can reduce data sent to the browser and serialization time.
zmin and zmax map data values to the image color range. For go.Image, these bounds must be specified for every channel.
Follow-up: How does this differ from px.imshow? px.imshow can accept a scalar bound and reuse it across channels, while go.Image requires channel-wise bounds.
go.Heatmapgo.layout.Imagepx.imshow