Skip to content

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
  1. 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.
  2. 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, Using bingroup, traces under barmode overlay and on different axes (of the same axis type) can have compatible bin settings. Note that histogram and histogram2d* trace can share the same bingroup
  3. Sets the source reference on Chart Studio Cloud for customdata.
  4. Sets the source reference on Chart Studio Cloud for arrayminus.
  5. Sets the source reference on Chart Studio Cloud for array.
  6. Sets the source reference on Chart Studio Cloud for arrayminus.
  7. Sets the source reference on Chart Studio Cloud for array.
  8. Sets the source reference on Chart Studio Cloud for hoverinfo.
  9. Sets the source reference on Chart Studio Cloud for align.
  10. Sets the source reference on Chart Studio Cloud for bgcolor.
  11. Sets the source reference on Chart Studio Cloud for bordercolor.
  12. Sets the source reference on Chart Studio Cloud for color.
  13. 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.
  14. Sets the source reference on Chart Studio Cloud for family.
  15. Sets the source reference on Chart Studio Cloud for lineposition.
  16. 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.
  17. Sets the source reference on Chart Studio Cloud for shadow.
  18. Sets the source reference on Chart Studio Cloud for size.
  19. Sets the source reference on Chart Studio Cloud for style.
  20. Sets the source reference on Chart Studio Cloud for textcase.
  21. Sets the source reference on Chart Studio Cloud for variant.
  22. Sets the source reference on Chart Studio Cloud for weight.
  23. Sets the source reference on Chart Studio Cloud for namelength.
  24. 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 in hovertemplate 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 are arrayOk: true) are available. Finally, the template string has access to variable binNumber 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>.
  25. Sets the source reference on Chart Studio Cloud for hovertemplate.
  26. Same as text.
  27. Sets the source reference on Chart Studio Cloud for hovertext.
  28. Sets the source reference on Chart Studio Cloud for ids.
  29. 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.
  30. 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.
  31. 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.
  32. 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.
  33. 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.
  34. Sets the title of the legend group.
  35. 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.
  36. 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.
  37. 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
  38. Sets a tick label prefix.
  39. Sets a tick label suffix.
  40. Sets the source reference on Chart Studio Cloud for ticktext.
  41. Sets the source reference on Chart Studio Cloud for tickvals.
  42. 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.
  43. 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.
  44. Sets the title of the color bar.
  45. Sets the source reference on Chart Studio Cloud for color.
  46. Sets the source reference on Chart Studio Cloud for color.
  47. Sets the source reference on Chart Studio Cloud for width.
  48. Sets the source reference on Chart Studio Cloud for opacity.
  49. Sets the source reference on Chart Studio Cloud for bgcolor.
  50. Sets the source reference on Chart Studio Cloud for fgcolor.
  51. Sets the source reference on Chart Studio Cloud for shape.
  52. Sets the source reference on Chart Studio Cloud for size.
  53. Sets the source reference on Chart Studio Cloud for solidity.
  54. Sets the source reference on Chart Studio Cloud for meta.
  55. Sets the trace name. The trace name appears as the legend item and on hover.
  56. 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.
  57. 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.
  58. 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.
  59. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  60. 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.
  61. 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.
  62. 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.
  63. Sets the source reference on Chart Studio Cloud for text.
  64. 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 are arrayOk: true) are available. Finally, the template string has access to variables label and value.
  65. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  66. 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 using xaxis.hoverformat.
  67. Sets the source reference on Chart Studio Cloud for x.
  68. 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 using yaxis.hoverformat.
  69. Sets the source reference on Chart Studio Cloud for y.