I have a dataset for which Mathematica easily creates a Histogram
. However I also need Mathematica to show error bars corresponding to 3 standard deviations for each bar. This is something similar to the ErrorBar
function for BarChart
. I cannot find any way to do this.
The difference between my case and the ErrorBar
package avaliable (http://reference.wolfram.com/language/ErrorBarPlots/ref/ErrorBar.html) is that it requires data for the magnitude of error for each bin/bar. In my case, I am giving Mathematica a raw data file to plot into a Histogram
. It should be able to calculate the error by itself. There is no way in which I can give Mathematica the bar heights, bin boundaries and corresponding errors from which it will give me a histogram. If someone can point that out, even that would be a potential solution to my problem. The ErrorBar
method works for BarChart
s, not Histogram
s as I understand.
Could anyone help?
Update:
Using the code @kglr helped me with I could implement the error bars in my Histogram. It is a Histogram that takes its y-values as {"Log","Count"}. So some modification was required.
ceF[d_: .2, nsd_: 3, color_: Automatic][cedf_: "Rectangle"] :=
Module[{e =
nsd Sqrt[Exp[#[[2, 2]]]]}, {ChartElementData[cedf][##], Thick,
color /.
Automatic -> Darker[Charting`ChartStyleInformation["Color"]],
If[Exp[#[[2, 2]]] - e != 0,
{Line[{{Mean@#[[1]], Log[Exp[#[[2, 2]]] - e]}, {Mean@#[[1]],
Log[Exp[#[[2, 2]]] + e]}}],
Line[{{#[[1, 1]] + d/2,
Log[Exp[#[[2, 2]]] - e]}, {#[[1, 2]] - d/2,
Log[Exp[#[[2, 2]]] - e]}}],
Line[{{#[[1, 1]] + d/2,
Log[Exp[#[[2, 2]]] + e]}, {#[[1, 2]] - d/2,
Log[Exp[#[[2, 2]]] + e]}}]},
{Line[{{Mean@#[[1]], 0}, {Mean@#[[1]],
Log[Exp[#[[2, 2]]] + e]}}],
Line[{{#[[1, 1]] + d/2, 0}, {#[[1, 2]] - d/2, 0}}],
Line[{{#[[1, 1]] + d/2,
Log[Exp[#[[2, 2]]] + e]}, {#[[1, 2]] - d/2,
Log[Exp[#[[2, 2]]] + e]}}]}
]
}] &
Incidentally the highest bin of my histogram faces this issue where Exp[#[[2, 2]]] - e is exactly zero. This modification should have been able to solve the issue but what I get is this,
and I don't know why the Bars dont start from the zero of the axis. That is to say, the bars should be starting from the y-tic marked "1", but they are starting from somewhere above "3." Why is that so? What do I do to make it start from "1"?
Incidentally, for the people who think this is a duplicate of the linked Q/A's, I'm sorry I could not make the connection since I am not an expert at Mathematica. However, the last time I looked it was not called Mathematica StackExchange for Experts Only. Please have this much respect for another person to realise that he would not have posted the question explaining why it is not a duplicate if he could solve the problem from there. I am a professional and my time and energy has some value. I would not be here if I could solve the problem by myself.
"Count"
(or"PDF"
) , how would you calculate "3 standard deviations for each bar"? $\endgroup$Log
scale.... :) $\endgroup$