Histogram2dcontour
Overview
The histogram2dcontour
trace type is used to create 2D contour plots that represent the density of data points across two dimensions. Similar to a 2D histogram, this plot type bins data along the x and y axes but visualizes the density using contour lines instead of filled colors.
You can customize the binning along both axes, contour lines, and the color mapping to suit your data. This trace type is useful for visualizing patterns and clusters in bivariate data.
Common Uses
- Density Contours: Showing how data points are distributed and clustered.
- Joint Distribution Analysis: Visualizing the relationship between two variables with density contours.
- Bivariate Statistical Analysis: Analyzing two variables and their joint behavior.
Check out the Attributes for the full set of configuration options
Examples
Common Configurations
Here's a simple histogram2dcontour
plot showing the density of data points using contour lines:
You can copy this code below to create this chart in your project:
models:
- name: histogram2dcontour-data
args:
- echo
- |
x,y
1,1
2,3
3,4
4,5
2,1
3,2
5,6
4,2
5,3
traces:
- name: Simple 2D Contour Histogram
model: ${ref(histogram2dcontour-data)}
props:
type: histogram2dcontour
x: ?{x}
y: ?{y}
colorscale: "Viridis"
contours:
coloring: "none"
charts:
- name: Simple 2D Contour Histogram
traces:
- ${ref(Simple 2D Contour Histogram)}
layout:
title:
text: Simple 2D Contour Histogram<br><sub>Density Contours of Bivariate Data</sub>
xaxis:
title:
text: "X Axis"
yaxis:
title:
text: "Y Axis"
This example demonstrates a histogram2dcontour
plot with filled contour regions to better visualize data density:
Here's the code:
models:
- name: histogram2dcontour-data-filled
args:
- echo
- |
x,y
2,1
3,2
4,3
5,4
6,5
3,1
4,2
5,3
6,4
traces:
- name: 2D Contour Histogram with Filled Contours
model: ${ref(histogram2dcontour-data-filled)}
props:
type: histogram2dcontour
x: ?{x}
y: ?{y}
colorscale: "Blues"
contours:
coloring: "heatmap"
charts:
- name: 2D Contour Histogram with Filled Contours
traces:
- ${ref(2D Contour Histogram with Filled Contours)}
layout:
title:
text: 2D Contour Histogram with Filled Contours<br><sub>Filled Density Contours</sub>
xaxis:
title:
text: "X Axis"
yaxis:
title:
text: "Y Axis"
Here's a histogram2dcontour
plot with custom bin sizes for both the x and y axes, allowing more control over the granularity of the plot:
Here's the code:
models:
- name: histogram2dcontour-data-bins
args:
- echo
- |
x,y
1,5
2,6
3,7
2,4
3,5
4,6
5,8
4,3
5,4
traces:
- name: 2D Contour Histogram with Custom Bins
model: ${ref(histogram2dcontour-data-bins)}
props:
type: histogram2dcontour
x: ?{x}
y: ?{y}
xbins:
size: 1
ybins:
size: 1
colorscale: "Jet"
charts:
- name: 2D Contour Histogram with Custom Bins
traces:
- ${ref(2D Contour Histogram with Custom Bins)}
layout:
title:
text: 2D Contour Histogram with Custom Bins<br><sub>Custom Bin Sizes for X and Y</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 histogram2dcontour
. You would configure these attributes on the trace with the trace.props
object.
autobinx: boolean
autobiny: boolean
autocolorscale: boolean
autocontour: boolean
bingroup: 'string' #(1)!
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' #(2)!
lineposition: any
shadow: 'string' #(3)!
size: number
style: any
textcase: any
variant: any
weight: integer
tickformat: 'string' #(4)!
tickformatstops: array
ticklabeloverflow: any
ticklabelposition: any
ticklabelstep: integer
ticklen: number
tickmode: any
tickprefix: 'string' #(5)!
ticks: any
ticksuffix: 'string' #(6)!
ticktext: array
ticktextsrc: 'string' #(7)!
tickvals: array
tickvalssrc: 'string' #(8)!
tickwidth: number
title:
font:
color: any
family: 'string' #(9)!
lineposition: any
shadow: 'string' #(10)!
size: number
style: any
textcase: any
variant: any
weight: integer
side: any
text: 'string' #(11)!
x: number
xanchor: any
xpad: number
xref: any
y: number
yanchor: any
ypad: number
yref: any
colorscale: any
contours:
coloring: any
end: number
impliedEdits: any
labelfont:
color: any
family: 'string' #(12)!
lineposition: any
shadow: 'string' #(13)!
size: number
style: any
textcase: any
variant: any
weight: integer
labelformat: 'string' #(14)!
operation: any
showlabels: boolean
showlines: boolean
size: number
start: number
type: any
customdata: array
customdatasrc: 'string' #(15)!
histfunc: any
histnorm: any
hoverinfo: array
hoverinfosrc: 'string' #(16)!
hoverlabel:
align: array
alignsrc: 'string' #(17)!
bgcolor: array
bgcolorsrc: 'string' #(18)!
bordercolor: array
bordercolorsrc: 'string' #(19)!
font:
color: array
colorsrc: 'string' #(20)!
family: 'string | array' #(21)!
familysrc: 'string' #(22)!
lineposition: array
linepositionsrc: 'string' #(23)!
shadow: 'string | array' #(24)!
shadowsrc: 'string' #(25)!
size: array
sizesrc: 'string' #(26)!
style: array
stylesrc: 'string' #(27)!
textcase: array
textcasesrc: 'string' #(28)!
variant: array
variantsrc: 'string' #(29)!
weight: array
weightsrc: 'string' #(30)!
namelength: array
namelengthsrc: 'string' #(31)!
hovertemplate: 'string | array' #(32)!
hovertemplatesrc: '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
marker:
color: array
colorsrc: 'string' #(40)!
metasrc: 'string' #(41)!
name: 'string' #(42)!
nbinsx: integer
nbinsy: integer
ncontours: integer
opacity: number
reversescale: boolean
showlegend: boolean
showscale: boolean
stream:
maxpoints: number
token: 'string' #(43)!
textfont:
color: any
family: 'string' #(44)!
lineposition: any
shadow: 'string' #(45)!
size: number
style: any
textcase: any
variant: any
weight: integer
texttemplate: 'string' #(46)!
type: histogram2dcontour
uid: 'string' #(47)!
visible: any
x: array
xaxis: string
xbingroup: 'string' #(48)!
xbins: {}
xcalendar: any
xhoverformat: 'string' #(49)!
xsrc: 'string' #(50)!
y: array
yaxis: string
ybingroup: 'string' #(51)!
ybins: {}
ycalendar: any
yhoverformat: 'string' #(52)!
ysrc: 'string' #(53)!
z: array
zauto: boolean
zhoverformat: 'string' #(54)!
zmax: number
zmid: number
zmin: number
zsrc: 'string' #(55)!
- Set the
xbingroup
andybingroup
default prefix For example, setting abingroup
of 1 on two histogram2d traces will make them their x-bins and y-bins match separately. - 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. Finally, the template string has access to variablez
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
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
color
. - 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.
- 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.
- Set a group of histogram traces which will have compatible x-bin settings. Using
xbingroup
, histogram2d and histogram2dcontour traces (on axes of the same axis type) can have compatible x-bin settings. Note that the samexbingroup
value can be used to set (1D) histogrambingroup
- 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
. - Set a group of histogram traces which will have compatible y-bin settings. Using
ybingroup
, histogram2d and histogram2dcontour traces (on axes of the same axis type) can have compatible y-bin settings. Note that the sameybingroup
value can be used to set (1D) histogrambingroup
- 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
.