# Easy way to create an histogram with given heights? [closed]

What is the easiest way to create an histogram with the heights of each bin already determined? I read all the support page on histograms but I don't understand if there is a way to create an histogram simply having a list of bins and a list of heights for heach bin. Does anyone have suggestion?

• Maybe BarChart. Or you could just use ListPlot. – march Feb 8 '16 at 22:45
• data = Table[RandomReal[10], {100}]; BarChart[data] – David G. Stork Feb 8 '16 at 22:47
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Feb 8 '16 at 23:21

Suppose your data is in the form:

myData = {{3, 6}, {4, 9}, {6, 10}};


meaning you want a histogram bar at position 3 of height 6, a bar at 4 of height 9, and so on.

Then to get a true histogram, you can do this:

Histogram[Flatten[Table[#[[1]], #[[2]]] & /@ myData], 10]


or

Histogram[Flatten[Table @@@ myData], 10]


Having a true histogram makes it a bit easier to change the width of bins (Histogram[Flatten[Table[#[[1]], #[[2]]] & /@ myData], 5]).

It depends on what you want.

A hack is to generate data according to your bins.

myData = {{1, 15}, {3, 6}, {4, 9}, {6, 10}};
Histogram[Flatten[ConstantArray[#[[1]], #[[2]]]& /@ myData], {1, 10, 1}]


Otherwise you can also be more explicit an exploit the fact the the Histogram function allows you to specify functions for both the bins and the counts. However it is important to understand that your bins have the meaning of: # of items in interval [min,max). Let's say we have our data as:

myData = {{1, 15}, {3, 6}, {4, 9}, {6, 10}, {7, 0}};


with the meaning 15 in [1,3), 6 in [3,4),... and 10 in [6,7) You see the last one is just for saying how large the last bin is. Now you can use:

Second[x_] := x[[2]]
Histogram[Drop[Map[First, myData], -1], Map[First, myData] &, Drop[Map[Second, myData], -1] &]


• Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Feb 9 '16 at 9:55