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):

enter image description here

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, 

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.

  • $\begingroup$ 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 $\endgroup$ – bill s Apr 11 '13 at 4:37
  • $\begingroup$ @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. $\endgroup$ – ZKT Apr 11 '13 at 4:42
  • 2
    $\begingroup$ @Zahra actually this is not a histogram with the traditional meaning its more like a step plot. $\endgroup$ – Spawn1701D Apr 11 '13 at 4:51
  • $\begingroup$ Of course you can make them with Mathematica. But you need to learn how to use the documentation. ? is your friend. $\endgroup$ – bill s Apr 11 '13 at 4:52
  • 1
    $\begingroup$ I note that not all pluses have the same size. Apparently they are error margins. Shouldn't that be incorporated as well? $\endgroup$ – 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]


enter image description here

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:

errors = Abs[PadRight[montecarlo,#]-PadRight[data,#]]&@Max[Length/@{montecarlo, data}]
g2eb = ErrorListPlot[Array[{{# - .5, data[[#]]}, ErrorBar[.5, errors[[#]]]} &, Length[data]], 
                     PlotStyle -> Red];
Show[g1, g2eb]

enter image description here

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.

|improve this answer|||||
  • $\begingroup$ Thanks a lot. This is great. Exactly what I was looking for. ;) $\endgroup$ – ZKT Apr 11 '13 at 5:10
  • $\begingroup$ In the OP plot the plot markers are in the middle of the stair steps. $\endgroup$ – Sjoerd C. de Vries Apr 11 '13 at 5:21
  • $\begingroup$ @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. $\endgroup$ – 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}]

enter image description here

|improve this answer|||||

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.