Contour
Overview
The contour
trace type is used to create contour plots, which are useful for visualizing three-dimensional data in two dimensions. Contour plots are often used to represent things like elevation, temperature, or pressure distributions. The trace uses a matrix of Z values and optional X and Y coordinates to create a continuous representation of the data.
Contour traces allow you to customize line colors, fill colors, and the number of contour levels to highlight data variation.
Common Uses
- Topographic Maps: Visualizing elevation levels across a geographic area.
- Heat or Temperature Maps: Displaying temperature distributions over a surface.
- Electromagnetic Fields: Representing the strength of a field at various points.
- Pressure Levels: Visualizing pressure across different areas in meteorology.
Check out the Attributes for the full set of configuration options
Examples
Common Configurations
Here's a simple contour
plot showing a basic grid of Z values, where X and Y represent spatial data:
You can copy this code below to create this chart in your project:
models:
- name: contour-data
args:
- echo
- |
x,y,z
1,1,10
2,1,15
3,1,20
4,1,25
5,1,30
1,2,5
2,2,10
3,2,15
4,2,20
5,2,25
1,3,0
2,3,5
3,3,10
4,3,15
5,3,20
1,4,5
2,4,10
3,4,15
4,4,20
5,4,25
1,5,10
2,5,15
3,5,20
4,5,25
5,5,30
traces:
- name: Simple Contour Plot
model: ${ref(contour-data)}
props:
type: contour
z:
- ?{x}
- ?{y}
- ?{z}
colorscale: "Viridis"
ncontours: 20
charts:
- name: Simple Contour Chart
traces:
- ${ref(Simple Contour Plot)}
layout:
title:
text: Simple Contour Plot<br><sub>Contour Plot Based on Z Values</sub>
xaxis:
title:
text: "X Axis"
yaxis:
title:
text: "Y Axis"
This example shows a contour plot with filled contours, where each level is shaded with a different color:
Here's the code:
models:
- name: contour-data-filled
args:
- echo
- |
x,y,z
0,0,10
1,0,15
2,0,20
3,0,25
4,0,30
0,1,5
1,1,10
2,1,15
3,1,20
4,1,25
0,2,0
1,2,5
2,2,10
3,2,15
4,2,20
0,3,5
1,3,10
2,3,15
3,3,20
4,3,25
0,4,10
1,4,15
2,4,20
3,4,25
4,4,30
traces:
- name: Filled Contour Plot
model: ${ref(contour-data-filled)}
props:
type: contour
x: ?{x}
y: ?{y}
z: ?{z}
colorscale: "Earth"
contours:
coloring: "heatmap"
showlines: true
ncontours: 25
charts:
- name: Filled Contour Chart
traces:
- ${ref(Filled Contour Plot)}
layout:
title:
text: Filled Contour Plot<br><sub>Contour Plot with Filled Levels</sub>
xaxis:
title:
text: "X Axis"
yaxis:
title:
text: "Y Axis"
This example demonstrates how to customize the contour levels by specifying a set number of levels:
Here's the code:
models:
- name: contour-data-multi
args:
- echo
- |
x,y,z
-3,-3,0
-2,-3,1
-1,-3,2
0,-3,3
1,-3,4
2,-3,5
3,-3,6
-3,-2,1
-2,-2,2
-1,-2,3
0,-2,4
1,-2,5
2,-2,6
3,-2,7
-3,-1,2
-2,-1,3
-1,-1,4
0,-1,5
1,-1,6
2,-1,7
3,-1,8
-3,0,3
-2,0,4
-1,0,5
0,0,6
1,0,7
2,0,8
3,0,9
-3,1,4
-2,1,5
-1,1,6
0,1,7
1,1,8
2,1,9
3,1,10
-3,2,5
-2,2,6
-1,2,7
0,2,8
1,2,9
2,2,10
3,2,11
-3,3,6
-2,3,7
-1,3,8
0,3,9
1,3,10
2,3,11
3,3,12
traces:
- name: Contour Plot with Multiple Levels
model: ${ref(contour-data-multi)}
props:
type: contour
x: ?{x}
y: ?{y}
z: ?{z}
colorscale: "Jet"
contours:
start: 0
end: 12
size: 0.5
ncontours: 24
charts:
- name: Contour Chart with Multiple Levels
traces:
- ${ref(Contour Plot with Multiple Levels)}
layout:
title:
text: Contour Plot with Multiple Levels<br><sub>Custom Contour Levels</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 contour
. You would configure these attributes on the trace with the trace.props
object.
autocolorscale: boolean
autocontour: boolean
coloraxis: string
colorbar:
bgcolor: any
bordercolor: any
borderwidth: number
exponentformat: any
len: number
lenmode: any
minexponent: number
nticks: integer
orientation: any
outlinecolor: any
outlinewidth: number
separatethousands: boolean
showexponent: any
showticklabels: boolean
showtickprefix: any
showticksuffix: any
thickness: number
thicknessmode: any
tickangle: number
tickcolor: any
tickfont:
color: any
family: 'string' #(1)!
lineposition: any
shadow: 'string' #(2)!
size: number
style: any
textcase: any
variant: any
weight: integer
tickformat: 'string' #(3)!
tickformatstops: array
ticklabeloverflow: any
ticklabelposition: any
ticklabelstep: integer
ticklen: number
tickmode: any
tickprefix: 'string' #(4)!
ticks: any
ticksuffix: 'string' #(5)!
ticktext: array
ticktextsrc: 'string' #(6)!
tickvals: array
tickvalssrc: 'string' #(7)!
tickwidth: number
title:
font:
color: any
family: 'string' #(8)!
lineposition: any
shadow: 'string' #(9)!
size: number
style: any
textcase: any
variant: any
weight: integer
side: any
text: 'string' #(10)!
x: number
xanchor: any
xpad: number
xref: any
y: number
yanchor: any
ypad: number
yref: any
colorscale: any
connectgaps: boolean
contours:
coloring: any
end: number
impliedEdits: any
labelfont:
color: any
family: 'string' #(11)!
lineposition: any
shadow: 'string' #(12)!
size: number
style: any
textcase: any
variant: any
weight: integer
labelformat: 'string' #(13)!
operation: any
showlabels: boolean
showlines: boolean
size: number
start: number
type: any
customdata: array
customdatasrc: 'string' #(14)!
dx: number
dy: number
fillcolor: any
hoverinfo: array
hoverinfosrc: 'string' #(15)!
hoverlabel:
align: array
alignsrc: 'string' #(16)!
bgcolor: array
bgcolorsrc: 'string' #(17)!
bordercolor: array
bordercolorsrc: 'string' #(18)!
font:
color: array
colorsrc: 'string' #(19)!
family: 'string | array' #(20)!
familysrc: 'string' #(21)!
lineposition: array
linepositionsrc: 'string' #(22)!
shadow: 'string | array' #(23)!
shadowsrc: 'string' #(24)!
size: array
sizesrc: 'string' #(25)!
style: array
stylesrc: 'string' #(26)!
textcase: array
textcasesrc: 'string' #(27)!
variant: array
variantsrc: 'string' #(28)!
weight: array
weightsrc: 'string' #(29)!
namelength: array
namelengthsrc: 'string' #(30)!
hoverongaps: boolean
hovertemplate: 'string | array' #(31)!
hovertemplatesrc: 'string' #(32)!
hovertext: array
hovertextsrc: 'string' #(33)!
ids: array
idssrc: 'string' #(34)!
legend: string
legendgroup: 'string' #(35)!
legendgrouptitle:
font:
color: any
family: 'string' #(36)!
lineposition: any
shadow: 'string' #(37)!
size: number
style: any
textcase: any
variant: any
weight: integer
text: 'string' #(38)!
legendrank: number
legendwidth: number
line:
color: any
dash: 'string' #(39)!
smoothing: number
width: number
metasrc: 'string' #(40)!
name: 'string' #(41)!
ncontours: integer
opacity: number
reversescale: boolean
showlegend: boolean
showscale: boolean
stream:
maxpoints: number
token: 'string' #(42)!
text: array
textfont:
color: any
family: 'string' #(43)!
lineposition: any
shadow: 'string' #(44)!
size: number
style: any
textcase: any
variant: any
weight: integer
textsrc: 'string' #(45)!
texttemplate: 'string' #(46)!
transpose: boolean
type: contour
uid: 'string' #(47)!
visible: any
x: array
xaxis: string
xcalendar: any
xhoverformat: 'string' #(48)!
xperiodalignment: any
xsrc: 'string' #(49)!
xtype: any
y: array
yaxis: string
ycalendar: any
yhoverformat: 'string' #(50)!
yperiodalignment: any
ysrc: 'string' #(51)!
ytype: any
z: array
zauto: boolean
zhoverformat: 'string' #(52)!
zmax: number
zmid: number
zmin: number
zorder: integer
zsrc: 'string' #(53)!
- 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 tick label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46
- Sets a tick label prefix.
- Sets a tick label suffix.
- Sets the source reference on Chart Studio Cloud for
ticktext
. - Sets the source reference on Chart Studio Cloud for
tickvals
. - 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 color bar.
- 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 contour label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format.
- 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. 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
. - Sets the legend group for this trace. Traces and shapes part of the same legend group hide/show at the same time when toggling legend items.
- 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 dash style of lines. Set to a dash type string (solid, dot, dash, longdash, dashdot, or longdashdot) or a dash length list in px (eg 5px,10px,2px,2px).
- 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.
- The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
- 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 source reference on Chart Studio Cloud for
text
. - For this trace it only has an effect if
coloring
is set to heatmap. Template string used for rendering the information text that appear on points. Note that this will overridetextinfo
. Variables are inserted using %{variable}, for example "y: %{y}". 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. Every attributes that can be specified per-point (the ones that arearrayOk: true
) are available. Finally, the template string has access to variablesx
,y
,z
andtext
. - Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
- Sets the hover text formatting rulefor
x
using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted usingxaxis.hoverformat
. - Sets the source reference on Chart Studio Cloud for
x
. - Sets the hover text formatting rulefor
y
using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted usingyaxis.hoverformat
. - Sets the source reference on Chart Studio Cloud for
y
. - Sets the hover text formatting rulefor
z
using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format.By default the values are formatted using generic number format. - Sets the source reference on Chart Studio Cloud for
z
.