2
$\begingroup$

If I have histogram as

Labeled[Histogram[{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                   1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2}, 
   ChartStyle -> Red, LabelStyle -> {18, GrayLevel[0]}],
   {Rotate[Style["Number of cities", FontFamily -> "Times"], 90 Degree],
   Style["Number of crimes", FontFamily -> "Times"]}, {Left, Bottom},
   LabelStyle -> {18, GrayLevel[0]}]

which looks like: enter image description here

How can I add error bars, let's say: $0.5$, $0.4$, and $0.3$, using Around command?

$\endgroup$
1
  • $\begingroup$ I don't think you can do that directly using Histogram. You can probably build your own histogram using BarChart and BinCounts, where you can use Around to specify error bars. Alternatively, you can keep the histogram and use ListPlot and BinCounts to genereate the error bars, which you could the combine with the histogram using Show $\endgroup$
    – Lukas Lang
    Commented Aug 5, 2021 at 11:39

1 Answer 1

1
$\begingroup$

You can use HistogramList and count between say 0 to 3 with stepsize 1.

h = HistogramList[{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 
                   1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2}, {0, 3, 1}];
nh = Length[h[[2]]]
err = {0.5, 0.4, 0.3}; (*set by hand*)
ListPlot[Table[{h[[1, i]], Around[h[[2, i]], err[[i]]]}, {i, nh}]]
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.