According to the Mathematica documentation the HistogramList command allows to specify a height function fh, as third argument, that allows to compute the height based on the bin location and the bin count.


The command HistogramDistribution seems to be related but, according to the documentation, has only the binning options of HistogramList.

Is it possible to influence the height of the bins of a HistogramDistribution or to generate such a distribution from a HistogramList?

Another option would be to change the HistogramDistribution after creating it. The meaning of the elements of this structure seems quite obvious, but I lack knowledge how to change the structure. Trying to change it in the obvious way, histdist[[2]] = {{...}} seems to break it.

  • $\begingroup$ Do you really mean HistoryList and HistoryDistribution? $\endgroup$
    – bill s
    Apr 20 '16 at 20:02
  • $\begingroup$ Does the example in HistogramList >>Scope >> Height Specifications help? $\endgroup$
    – kglr
    Apr 20 '16 at 20:20
  • $\begingroup$ @bill HistogramList and HistogramDistribution $\endgroup$
    – highsciguy
    Apr 20 '16 at 20:53

Update: You can replace the vector of PDFValues (i.e., Part (2,1)) of the DataDistribution object returned by HistogramDistribution with a vector that has the same length and sum.

data1 = RandomVariate[NormalDistribution[], 100];
D1 = HistogramDistribution[data1];
D2 = D1;
D2[[2, 1]] =  N@Total[D1["PDFValues"]] 
            Normalize[RandomInteger[10, {Length@D1["PDFValues"]}], Total];


{0.02, 0.18, 0.38, 0.24, 0.14, 0.02, 0.02}


{0.236842, 0.105263, 0.184211, 0.263158, 0.157895, 0.0526316, 0.}

Row[DiscretePlot[PDF[#, x], {x, -4, 4, .01}, ImageSize -> 300]& /@ {D1, D2}, Spacer[10]]

Mathematica graphics

Through[{Mean, Median, Variance,  Moment[#, 2] &}@#] & /@ {D1, D2}

{{-0.06, -0.210526, 1.44973, 1.45333},
{-0.342105, -0.142857, 2.47946, 2.59649}}

Replace Normalize[RandomInteger[10, {Length@D1["PDFValues"]}], Total] with your choice of a vector that has appropriate length and sum.

Previous version:

From Histogram >> Details:

Mathematica graphics

And from HistogramList >> Details:

Mathematica graphics

And mimicking the example in HistogramList >> Scope >> Height Specifications

data = RandomVariate[NormalDistribution[0, 1], 100];

accumulatedCount[bins_, counts_] := Accumulate[counts]
Row@{Histogram[data, {1}, ImageSize -> 300], 
  Histogram[data, {1}, accumulatedCount, ImageSize -> 300]}

Mathematica graphics

we can construct custom height functions like:

foo1[bins_, counts_] := bins[[All, 1]]^2;
foo2[bins_, counts_] := Range[Length@counts];

Row@{Histogram[data, {1}, ImageSize -> 300],
  Histogram[data, {1}, foo1, ImageSize -> 300],
  Histogram[data, {1}, foo2, ImageSize -> 300]}

Mathematica graphics

The only requirement is that the height function returns a list of length that is equal to the number of bins:

See also: this answer to a related question for an example of how to construct a custom 3D height function for Histogram3D.

  • $\begingroup$ Thanks, this tells me how to use the height function of HistogramList but I need a HistogramDistribution, not only to plot a histogram but also for statistical operations (strictly speaking I do not need it normalized). $\endgroup$
    – highsciguy
    Apr 20 '16 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.