Image
Overview
The image
trace type is used to display raster images in a plot. This is particularly useful for visualizing images as data or overlaying images on other plot types. The image trace allows for the rendering of pixel data in a 2D grid.
You can customize the image size, position, and color scaling to represent image data effectively. Images can be used in scientific visualizations, geographic data, or any scenario where image data is needed.
Common Uses
- Raster Images: Displaying raster images in data visualizations.
- Geographic Maps: Visualizing maps or satellite images.
- Image Data: Rendering images directly as part of data exploration and analysis.
Check out the Attributes for the full set of configuration options
Examples
Common Configurations
Here's a simple image
plot displaying an image based on pixel values:
You can copy this code below to create this chart in your project:
models:
- name: image-data
args:
- echo
- |
z
0,0,1,1
1,0,0,1
1,1,0,0
traces:
- name: Simple Image Plot
model: ${ref(image-data)}
props:
type: image
z: ?{z}
charts:
- name: Simple Image Chart
traces:
- ${ref(Simple Image Plot)}
layout:
title:
text: Simple Image Plot<br><sub>Raster Image Display</sub>
This example demonstrates an image
plot with a custom colorscale to better represent the image data:
Here's the code:
models:
- name: image-data-custom
args:
- echo
- |
z
0.1,0.2,0.3,0.4
0.5,0.6,0.7,0.8
0.9,1.0,0.2,0.3
traces:
- name: Image Plot with Custom Colorscale
model: ${ref(image-data-custom)}
props:
type: image
z: ?{z}
colorscale: "Viridis"
charts:
- name: Image Plot with Custom Colorscale
traces:
- ${ref(Image Plot with Custom Colorscale)}
layout:
title:
text: Image Plot with Custom Colorscale<br><sub>Custom Coloring for Image Data</sub>
This example shows an image
plot with axis labels and annotations to provide context for the image data:
Here's the code:
models:
- name: image-data-annotated
args:
- echo
- |
z
1,0,0,1
0,1,1,0
0,0,1,1
traces:
- name: Image Plot with Axis Annotations
model: ${ref(image-data-annotated)}
props:
type: image
z: ?{z}
charts:
- name: Image Plot with Axis Annotations
traces:
- ${ref(Image Plot with Axis Annotations)}
layout:
title:
text: Image Plot with Axis Annotations<br><sub>Image with Axes</sub>
xaxis:
title:
text: "X Axis"
yaxis:
title:
text: "Y Axis"
A schema to validate plotly trace properties
Attributes
These attributes apply to traces where trace.props.type
is set to image
. You would configure these attributes on the trace with the trace.props
object.
colormodel: any
customdata: array
customdatasrc: 'string' #(1)!
dx: number
dy: number
hoverinfo: array
hoverinfosrc: 'string' #(2)!
hoverlabel:
align: array
alignsrc: 'string' #(3)!
bgcolor: array
bgcolorsrc: 'string' #(4)!
bordercolor: array
bordercolorsrc: 'string' #(5)!
font:
color: array
colorsrc: 'string' #(6)!
family: 'string | array' #(7)!
familysrc: 'string' #(8)!
lineposition: array
linepositionsrc: 'string' #(9)!
shadow: 'string | array' #(10)!
shadowsrc: 'string' #(11)!
size: array
sizesrc: 'string' #(12)!
style: array
stylesrc: 'string' #(13)!
textcase: array
textcasesrc: 'string' #(14)!
variant: array
variantsrc: 'string' #(15)!
weight: array
weightsrc: 'string' #(16)!
namelength: array
namelengthsrc: 'string' #(17)!
hovertemplate: 'string | array' #(18)!
hovertemplatesrc: 'string' #(19)!
hovertext: array
hovertextsrc: 'string' #(20)!
ids: array
idssrc: 'string' #(21)!
legend: string
legendgrouptitle:
font:
color: any
family: 'string' #(22)!
lineposition: any
shadow: 'string' #(23)!
size: number
style: any
textcase: any
variant: any
weight: integer
text: 'string' #(24)!
legendrank: number
legendwidth: number
metasrc: 'string' #(25)!
name: 'string' #(26)!
opacity: number
source: 'string' #(27)!
stream:
maxpoints: number
token: 'string' #(28)!
text: array
textsrc: 'string' #(29)!
type: image
uid: 'string' #(30)!
visible: any
xaxis: string
yaxis: string
z: array
zmax: array
zmin: array
zorder: integer
zsmooth: any
zsrc: 'string' #(31)!
- Sets the source reference on Chart Studio Cloud for
customdata
. - Sets the source reference on Chart Studio Cloud for
hoverinfo
. - Sets the source reference on Chart Studio Cloud for
align
. - Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the source reference on Chart Studio Cloud for
bordercolor
. - Sets the source reference on Chart Studio Cloud for
color
. - HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the source reference on Chart Studio Cloud for
lineposition
. - Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
style
. - Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the source reference on Chart Studio Cloud for
variant
. - Sets the source reference on Chart Studio Cloud for
weight
. - Sets the source reference on Chart Studio Cloud for
namelength
. - Template string used for rendering the information that appear on hover box. Note that this will override
hoverinfo
. Variables are inserted using %{variable}, for example "y: %{y}" as well as %{xother}, {%xother}, {%_xother}, {%xother_}. When showing info for several points, xother will be added to those with different x positions from the first point. An underscore before or after (x|y)other will add a space on that side, only when this field is shown. Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available inhovertemplate
are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that arearrayOk: true
) are available. Finally, the template string has access to variablesz
,color
andcolormodel
. Anything contained in tag<extra>
is displayed in the secondary box, for example "{fullData.name} ". To hide the secondary box completely, use an empty tag<extra></extra>
. - Sets the source reference on Chart Studio Cloud for
hovertemplate
. - Sets the source reference on Chart Studio Cloud for
hovertext
. - Sets the source reference on Chart Studio Cloud for
ids
. - HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
- Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
- Sets the title of the legend group.
- Sets the source reference on Chart Studio Cloud for
meta
. - Sets the trace name. The trace name appears as the legend item and on hover.
- Specifies the data URI of the image to be visualized. The URI consists of "data:image/[
][;base64]," - The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
- Sets the source reference on Chart Studio Cloud for
text
. - Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
- Sets the source reference on Chart Studio Cloud for
z
.