# Make good looking histograms from frequency data

I allways do my calculations in Mathematica and I make my histograms using ROOT language. However I am wondering is it possible to make good looking histogram inside Mathematica? A sample of what I mean is the following figure (made by ROOT):

Some sample data (not identical to the one used in the above plot) which can be used:

data = {154.081, 468.999, 648.538, 776.386, 899.310, 766.234, 596.229, 527.160, 443.315,
300.393, 216.542, 105.620, 53.7748, 29.0068, 21.4696, 8.92971, 8.63114, 5.70516,
60.5296};


using as the red pluses inside histogram and

montecarlo = {180.836, 492.187, 739.735, 894.031, 915.812, 841.874, 699.237, 556.588,
426.208, 303.230, 212.114, 133.295, 71.6399, 36.9657, 21.9234, 9.20245,
6.13829, 5.20975};


using as the best fit to the data. Note that both data sets are final frequency values and not the original data set on which Histogram could work.

• You can draw such plots using the ListPlot command. There are many options for color, style, etc. To get the plus signs, you would use the option PlotMarkers. You can access the help files for these commands using ?ListPlot – bill s Apr 11 '13 at 4:37
• @bill s Thanks a lot for your comment. What about the other joined plots? I guess that I can't make them using ListPlot and I don't know that Histogram can produce them or not. – ZKT Apr 11 '13 at 4:42
• @Zahra actually this is not a histogram with the traditional meaning its more like a step plot. – Spawn1701D Apr 11 '13 at 4:51
• Of course you can make them with Mathematica. But you need to learn how to use the documentation. ? is your friend. – bill s Apr 11 '13 at 4:52
• I note that not all pluses have the same size. Apparently they are error margins. Shouldn't that be incorporated as well? – Sjoerd C. de Vries Apr 11 '13 at 8:39

Try this

g1 = Plot[montecarlo[[Floor[n + 1]]], {n, 0, Length[montecarlo] - 1},
Exclusions -> Solid, PlotRange -> {{0, Length[montecarlo]}, All},
PlotStyle -> Green];

g2 = ListPlot[Thread[{Array[# - .5 &, Length[data]], data}], PlotMarkers -> Style["+", 18],
PlotStyle -> Red];
Show[g1, g2]


Result:

for further formatting of the image, axes, labels, legends look at the online help of Mathematica its very concise.

Taking into account Sjoerd C. de Vries' comment in mind, if you want the pluses to corespont to error bar you can use the following commands:

Needs["ErrorBarPlots"]
g2eb = ErrorListPlot[Array[{{# - .5, data[[#]]}, ErrorBar[.5, errors[[#]]]} &, Length[data]],
PlotStyle -> Red];
Show[g1, g2eb]


this is just a demonstration I need more information on what the errors denote for a faithful reproduction of ROOT's plot. If you have the errors as a list just substitute the value of my error variable.

• Thanks a lot. This is great. Exactly what I was looking for. ;) – ZKT Apr 11 '13 at 5:10
• In the OP plot the plot markers are in the middle of the stair steps. – Sjoerd C. de Vries Apr 11 '13 at 5:21
• @SjoerdC.deVries its a matter of a shifting, I make the change to reflect that. The sample data is different so the two plots can be qualitatively the same. – Spawn1701D Apr 11 '13 at 5:32

You can specify InterpolationOrder -> 0 in ListPlot, and you can specify different orders for different datasets:

ListPlot[{montecarlo, MapIndexed[{First@#2 + .5, #1} &, data]},
PlotMarkers -> {Spacer@0, Style["+", 18]},
Joined -> {True, False},
PlotStyle -> {Green, Red},
InterpolationOrder -> {0, 1}]
`