Histogram
Overview
The histogram
trace type is used to create histograms, which represent the distribution of numerical data by dividing the data into bins and counting the number of occurrences in each bin. Histograms are great for understanding data distribution, variability, and patterns.
You can customize bin size, orientation, and colors to fit your data. Histograms are especially useful in statistical analysis, data science, and exploratory data analysis.
Common Uses
- Data Distribution: Visualizing how data points are distributed across different ranges.
- Frequency Analysis: Showing the frequency of values within specific intervals.
- Statistical Summaries: Understanding the spread, central tendency, and outliers in data.
Check out the Attributes for the full set of configuration options
Examples
Common Configurations
Here's a simple histogram
plot showing the distribution of data across different bins:
You can copy this code below to create this chart in your project:
models:
- name: histogram-data
args:
- echo
- |
value
10
20
15
10
5
25
30
15
20
10
traces:
- name: Simple Histogram Plot
model: ${ref(histogram-data)}
props:
type: histogram
x: ?{value}
nbinsx: 5
marker:
color: "#17becf"
charts:
- name: Simple Histogram Chart
traces:
- ${ref(Simple Histogram Plot)}
layout:
title:
text: Simple Histogram Plot<br><sub>Data Distribution Across Bins</sub>
xaxis:
title:
text: "Value"
yaxis:
title:
text: "Count"
bargap: 0.05
This example shows a horizontal histogram
plot, where the bins are displayed along the y-axis:
Here's the code:
models:
- name: histogram-data-horizontal
args:
- echo
- |
value
1
3
2
5
4
3
3
3
3
4
1
3
4
3
3
4
1
2
3
5
2
3
4
traces:
- name: Horizontal Histogram Plot
model: ${ref(histogram-data-horizontal)}
props:
type: histogram
y: ?{value}
nbinsy: 2
marker:
color: "#ff7f0e"
orientation: h
charts:
- name: Horizontal Histogram Chart
traces:
- ${ref(Horizontal Histogram Plot)}
layout:
title:
text: Horizontal Histogram Plot<br><sub>Data Distribution in a Horizontal Format</sub>
yaxis:
title:
text: "Value"
xaxis:
title:
text: "Count"
bargap: 0.05
Here's a stacked histogram
plot showing the distribution of two different datasets stacked on top of each other:
Here's the code:
models:
- name: histogram-data-stacked
args:
- echo
- |
group,value
A,1
A,2
A,2
A,3
B,3
B,4
B,5
B,5
B,6
traces:
- name: Histogram Groups
model: ${ref(histogram-data-stacked)}
cohort_on: '"group"'
columns:
color: |
case
when "group" = 'A' Then '#1f77b4'
when "group" = 'B' THEN '#ff7f0e'
else null
end
props:
type: histogram
x: ?{value}
marker:
color: column(color)
charts:
- name: Stacked Histogram Chart
traces:
- ${ref(Histogram Groups)}
layout:
title:
text: Stacked Histogram Chart<br><sub>Data Distribution for Two Groups</sub>
xaxis:
title:
text: "Value"
yaxis:
title:
text: "Count"
barmode: "stack"
bargap: .05
A schema to validate plotly trace properties
Attributes
These attributes apply to traces where trace.props.type
is set to histogram
. You would configure these attributes on the trace with the trace.props
object.
alignmentgroup: 'string' #(1)!
autobinx: boolean
autobiny: boolean
bingroup: 'string' #(2)!
cliponaxis: boolean
constraintext: any
cumulative:
currentbin: any
direction: any
enabled: boolean
customdata: array
customdatasrc: 'string' #(3)!
error_x:
array: array
arrayminus: array
arrayminussrc: 'string' #(4)!
arraysrc: 'string' #(5)!
color: any
copy_ystyle: boolean
symmetric: boolean
thickness: number
traceref: integer
tracerefminus: integer
type: any
value: number
valueminus: number
visible: boolean
width: number
error_y:
array: array
arrayminus: array
arrayminussrc: 'string' #(6)!
arraysrc: 'string' #(7)!
color: any
symmetric: boolean
thickness: number
traceref: integer
tracerefminus: integer
type: any
value: number
valueminus: number
visible: boolean
width: number
histfunc: any
histnorm: any
hoverinfo: array
hoverinfosrc: 'string' #(8)!
hoverlabel:
align: array
alignsrc: 'string' #(9)!
bgcolor: array
bgcolorsrc: 'string' #(10)!
bordercolor: array
bordercolorsrc: 'string' #(11)!
font:
color: array
colorsrc: 'string' #(12)!
family: 'string | array' #(13)!
familysrc: 'string' #(14)!
lineposition: array
linepositionsrc: 'string' #(15)!
shadow: 'string | array' #(16)!
shadowsrc: 'string' #(17)!
size: array
sizesrc: 'string' #(18)!
style: array
stylesrc: 'string' #(19)!
textcase: array
textcasesrc: 'string' #(20)!
variant: array
variantsrc: 'string' #(21)!
weight: array
weightsrc: 'string' #(22)!
namelength: array
namelengthsrc: 'string' #(23)!
hovertemplate: 'string | array' #(24)!
hovertemplatesrc: 'string' #(25)!
hovertext: 'string | array' #(26)!
hovertextsrc: 'string' #(27)!
ids: array
idssrc: 'string' #(28)!
insidetextanchor: any
insidetextfont:
color: any
family: 'string' #(29)!
lineposition: any
shadow: 'string' #(30)!
size: number
style: any
textcase: any
variant: any
weight: integer
legend: string
legendgroup: 'string' #(31)!
legendgrouptitle:
font:
color: any
family: 'string' #(32)!
lineposition: any
shadow: 'string' #(33)!
size: number
style: any
textcase: any
variant: any
weight: integer
text: 'string' #(34)!
legendrank: number
legendwidth: number
marker:
autocolorscale: boolean
cauto: boolean
cmax: number
cmid: number
cmin: number
color: array
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' #(35)!
lineposition: any
shadow: 'string' #(36)!
size: number
style: any
textcase: any
variant: any
weight: integer
tickformat: 'string' #(37)!
tickformatstops: array
ticklabeloverflow: any
ticklabelposition: any
ticklabelstep: integer
ticklen: number
tickmode: any
tickprefix: 'string' #(38)!
ticks: any
ticksuffix: 'string' #(39)!
ticktext: array
ticktextsrc: 'string' #(40)!
tickvals: array
tickvalssrc: 'string' #(41)!
tickwidth: number
title:
font:
color: any
family: 'string' #(42)!
lineposition: any
shadow: 'string' #(43)!
size: number
style: any
textcase: any
variant: any
weight: integer
side: any
text: 'string' #(44)!
x: number
xanchor: any
xpad: number
xref: any
y: number
yanchor: any
ypad: number
yref: any
colorscale: any
colorsrc: 'string' #(45)!
line:
autocolorscale: boolean
cauto: boolean
cmax: number
cmid: number
cmin: number
color: array
coloraxis: string
colorscale: any
colorsrc: 'string' #(46)!
reversescale: boolean
width: array
widthsrc: 'string' #(47)!
opacity: array
opacitysrc: 'string' #(48)!
pattern:
bgcolor: array
bgcolorsrc: 'string' #(49)!
fgcolor: array
fgcolorsrc: 'string' #(50)!
fgopacity: number
fillmode: any
shape: array
shapesrc: 'string' #(51)!
size: array
sizesrc: 'string' #(52)!
solidity: array
soliditysrc: 'string' #(53)!
reversescale: boolean
showscale: boolean
metasrc: 'string' #(54)!
name: 'string' #(55)!
nbinsx: integer
nbinsy: integer
offsetgroup: 'string' #(56)!
opacity: number
orientation: any
outsidetextfont:
color: any
family: 'string' #(57)!
lineposition: any
shadow: 'string' #(58)!
size: number
style: any
textcase: any
variant: any
weight: integer
selected:
marker:
color: any
opacity: number
textfont:
color: any
showlegend: boolean
stream:
maxpoints: number
token: 'string' #(59)!
text: 'string | array' #(60)!
textangle: number
textfont:
color: any
family: 'string' #(61)!
lineposition: any
shadow: 'string' #(62)!
size: number
style: any
textcase: any
variant: any
weight: integer
textposition: any
textsrc: 'string' #(63)!
texttemplate: 'string' #(64)!
type: histogram
uid: 'string' #(65)!
unselected:
marker:
color: any
opacity: number
textfont:
color: any
visible: any
x: array
xaxis: string
xbins: {}
xcalendar: any
xhoverformat: 'string' #(66)!
xsrc: 'string' #(67)!
y: array
yaxis: string
ybins: {}
ycalendar: any
yhoverformat: 'string' #(68)!
ysrc: 'string' #(69)!
zorder: integer
- Set several traces linked to the same position axis or matching axes to the same alignmentgroup. This controls whether bars compute their positional range dependently or independently.
- Set a group of histogram traces which will have compatible bin settings. Note that traces on the same subplot and with the same orientation under
barmode
stack, relative and group are forced into the same bingroup, Usingbingroup
, traces underbarmode
overlay and on different axes (of the same axis type) can have compatible bin settings. Note that histogram and histogram2d* trace can share the samebingroup
- Sets the source reference on Chart Studio Cloud for
customdata
. - Sets the source reference on Chart Studio Cloud for
arrayminus
. - Sets the source reference on Chart Studio Cloud for
array
. - Sets the source reference on Chart Studio Cloud for
arrayminus
. - Sets the source reference on Chart Studio Cloud for
array
. - 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 variablebinNumber
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
. - Same as
text
. - 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 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.
- 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.
- Sets the source reference on Chart Studio Cloud for
color
. - Sets the source reference on Chart Studio Cloud for
color
. - Sets the source reference on Chart Studio Cloud for
width
. - Sets the source reference on Chart Studio Cloud for
opacity
. - Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the source reference on Chart Studio Cloud for
fgcolor
. - Sets the source reference on Chart Studio Cloud for
shape
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
solidity
. - 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.
- Set several traces linked to the same position axis or matching axes to the same offsetgroup where bars of the same position coordinate will line up.
- 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.
- 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 hover text elements associated with each bar. If a single string, the same string appears over all bars. If an array of string, the items are mapped in order to the this trace's coordinates.
- 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
. - Template string used for rendering the information text that appear on points. Note that this will override
textinfo
. 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 variableslabel
andvalue
. - 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
.