plots a density histogram of the values {xi,yi}.


plots a density histogram with bins specified by bspec.


plots a density histogram with bin densities computed according to the specification hspec.

Details and Options

  • DensityHistogram[data] by default plots a histogram with equal bins chosen to approximate an assumed underlying smooth distribution of the values {xi,yi}.
  • The width of each bin is computed according to the values xi, and the width according to the values yi.
  • The following bin specifications bspec can be given:
  • nuse n bins
    {w}use bins of width w
    {min,max,w}use bins of width w from min to max
    {{b1,b2,}}use bins [b1,b2),[b2,b3),
    Automaticdetermine bin widths automatically
    "name"use a named binning method
    {"Log",bspec}apply binning bspec on log transformed data
    fbapply fb to get an explicit bin specification {b1,b2,}
    {xspec,yspec}give different x and y specifications
  • The binning specification "Log" is taken to use the Automatic underlying binning method.
  • Possible named binning methods include:
  • "Sturges"compute the number of bins based on the length of data
    "Scott"asymptotically minimize the mean square error
    "FreedmanDiaconis"twice the interquartile range divided by the cube root of sample size
    "Knuth"balance likelihood and prior probability of a piecewise uniform model
    "Wand"one-level recursive approximate Wand binning
  • The function fb in DensityHistogram[data,fb] is applied to a list of all {xi,yi}, and should return an explicit bin list {{bx1,bx2,},{by1,by2,}}. In DensityHistogram[data,{fx,fy}], fx is applied to the list of xi, and fy to the list of yi.
  • Different forms of density histogram can be obtained by giving different bin density specifications hspec in DensityHistogram[data,bspec,hspec]. The following forms can be used:
  • "Count"number of elements in each bin
    "CumulativeCount"cumulative counts
    "SurvivalCount"survival counts
    "Probability"fraction of values lying in each bin
    "Intensity"counts divided by bin area
    "PDF"probability density function
    "CDF"cumulative distribution function
    "SF"survival function
    "HF"hazard function
    "CHF"cumulative hazard function
    {"Log",hspec}log transformed height specification
    fhheights obtained by applying fh to bins and counts
  • The function fh in DensityHistogram[data,bspec,fh] is applied to three arguments: a list of bins {{bx1,bx2},{bx2,},}, a list of bins {{by1,by2},{by2,},}, and the corresponding 2D array of counts {{c11,c12,},{c21,},}. The function should return an array of densities to be used for each of the cij.
  • Only values {xi,yi} that consist of real numbers are assigned to bins; others are taken to be missing.
  • DensityHistogram has the same options as Graphics with the following additions and changes:
  • AspectRatio1ratio of height to width
    ChartBaseStyleAutomaticoverall style for tiles
    ChartElementFunctionAutomatichow to generate raw graphics for tiles
    ClippingStyleNonehow to draw values clipped by PlotRange
    ColorFunctionAutomatichow to color the plot
    ColorFunctionScalingTruewhether to scale the argument to ColorFunction
    FrameTruewhether to draw a frame around the plot
    FrameTicksAutomaticframe tick marks
    LabelingFunctionAutomatichow to label elements
    MethodAutomaticthe method to use for refining the plot
    PerformanceGoal$PerformanceGoalaspects of performance to try to optimize
    PlotRangeAutomaticthe range of f or other values to include
    PlotRangeClippingTruewhether to clip at the plot range
    PlotRangePaddingAutomatichow much to pad the range of values
    PlotTheme$PlotThemeoverall theme for the plot
    ScalingFunctionsNonehow to scale individual coordinates
  • The arguments supplied to ChartElementFunction are the bin region {{xmin,xmax},{ymin,ymax}}, the bin values lists, and metadata {m1,m2,}.
  • The argument supplied to ColorFunction is the density for each bin.
  • With ScalingFunctions->{sx,sy,sz}, the coordinate is scaled using sx etc.
  • Style and other options are effectively applied in the order ChartBaseStyle, ColorFunction, and ChartElementFunction, with later specifications overriding earlier ones.


open all close all

Basic Examples  (2)

Plot a density histogram for a dataset:

Click for copyable input

Plot the probability density function of the data:

Click for copyable input
Click for copyable input

Cumulative distribution function:

Click for copyable input

Survival function:

Click for copyable input

Hazard function:

Click for copyable input

Cumulative hazard function:

Click for copyable input

Scope  (12)

Options  (21)

Applications  (3)

Properties & Relations  (4)

Neat Examples  (1)

Introduced in 2010
Updated in 2015