In the Add Error Bars to Charts and Plots How To in the Mathematica documentation a function ErrorBar
is given:
errorBar[type_: "Rectangle"][{{x0_, x1_}, {y0_, y1_}}, value_, meta_] :=
Block[{error},
error = Flatten[meta];
error = If[error === {}, 0, Last[error]];
{ChartElementData[type][{{x0, x1}, {y0, y1}}, value, meta],
{Black, Line[{
{{(x0 + x1)/2, y1 - error}, {(x0 + x1)/2, y1 + error}},
{{1/4 (3 x0 + x1), y1 + error}, {1/4 (x0 + 3 x1), y1 + error}},
{{1/4 (3 x0 + x1), y1 - error}, {1/4 (x0 + 3 x1), y1 - error}}
}]
}}
]
that adds error bars to BarChart
. Here is an example using some random data with random errors:
chartData = MapThread[{#1 -> #2} &, {RandomReal[1, 10], RandomReal[0.1, 10]}]
and some random labels:
labels = ToString /@ RandomReal[100000, 10]
Now plotting it, as per the tutorial:
BarChart[chartData, ChartElementFunction -> errorBar["Rectangle"],
ChartLabels -> Placed[labels, Axis, Rotate[#, Pi/2] &]]
The labels are:
{"99539.6", "17862.9", "14683.4", "32667.2", "42690.",
"70230.8", "59050.4", "59204.7", "9138.2", "19080.3"}
However, in the plot:
The first label is repeated incorrectly for all the bars, what's going on here? Without error bars the labels on the plot are correct:
BarChart[RandomReal[1, 10], ChartLabels -> Placed[labels, Axis, Rotate[#, Pi/2] &]]