1
$\begingroup$

This question already has an answer here:

I want to make a BarChart with Log-Scaling and Error-Bars.

I can do both individually:

TimeData = {3.33523 -> 2.72453, 1.14286 -> 0.74611, 1.02783 -> 0.815587, 3.6301 -> 2.42748}
BarChart[TimeData, ScalingFunctions -> "Log"]
BarChart[TimeData, ChartElementFunction -> errorBar["Rectangle"]]

And it gives me the expected results, but as soon as I add the two parameters together, i.e.

BarChart[TimeData, ChartElementFunction -> errorBar["Rectangle"], ScalingFunctions -> "Log"]

the scaling is logarithmic, but the error-bars stay linear, thus make not much sense. Is there any clever way to do it?

(A nasty work-around would be to calculate the errors in a logarithmic way, and then the linear plot of them would give the correct result, but that's defintiivly not a nice way)

$\endgroup$

marked as duplicate by NicoDean, bbgodfrey, Karsten 7., kglr plotting Feb 10 '15 at 16:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

The function errorBar can be found in the Documentation Center page How to -- Add Error Bars to Charts and Plots.

You can change the function errorBar to take a scaling function argument:

errorBar2[sf_: Identity, type_: "Rectangle"][{{x0_, x1_}, {y0_, y1_}}, value_, meta_] :=
 Block[{error, isf = InverseFunction[sf][y1]}, error = Flatten[meta]; 
  error = If[error == {}, {0, 0}, {sf[isf - #], sf[isf + #]} &@error];
  {ChartElementData[type][{{x0, x1}, {y0, y1}}, value, meta],
   {Thick, Dynamic@Darker@CurrentValue["Color"], 
    Line[{{{(x0 + x1)/2, error[[1, 1]]}, {(x0 + x1)/2, error[[2, 1]]}}, 
          {{1/4 (3 x0 + x1), error[[2, 1]]}, {1/4 (x0 + 3 x1), error[[2, 1]]}},
          {{1/4 (3 x0 + x1), error[[1, 1]]}, {1/4 (x0 + 3 x1), error[[1, 1]]}}}]}}]

Row[BarChart[TimeData, ScalingFunctions -> #, PlotLabel -> (Style[ScalingFunctions -> #, 16]),
   ChartStyle -> "DarkRainbow", ImageSize -> 400, 
   ChartElementFunction -> errorBar2[ToExpression[# /. None->"Identity"], "GlassRectangle"]] & /@
     {None, "Log"}, Spacer[10]]

enter image description here

Related Q/As: Spacing the elements in a bar chart with error bars and ErrorBars / other way of visualising deviation in Paired Bar Charts

$\endgroup$
  • $\begingroup$ @kugler Thank you, that looks very good. One thing I wonder: The symmetric errors in the linear plot should appear non-linear (logarithmic) in the log-plot, right? But in your example, they also seem symmetric. Do you know why that is? $\endgroup$ – NicoDean Feb 10 '15 at 14:04
  • $\begingroup$ @NicoDean, right -- Great observation! As is, errorBar produces symmetric errors, so does errorBar2. I will post an update with a fix. $\endgroup$ – kglr Feb 10 '15 at 14:30
  • $\begingroup$ I was just searching for that problem (it seems to exist in every type of log-scale error plotting), and found a very similar question: mathematica.stackexchange.com/questions/35462/… (i didn't see it before when I was writing the question). The answer shows how to manually scale the errors. $\endgroup$ – NicoDean Feb 10 '15 at 14:34
  • $\begingroup$ NicoDean, thank you for the link -- i was trying to do a similar modification. Since @ubpdqn's answer in the linked Q/A covers this question too, do you think this question should be marked as duplicate? $\endgroup$ – kglr Feb 10 '15 at 14:56
  • $\begingroup$ Yes I guess so :-/ Sorry. And strange that it didn't show up earlier. $\endgroup$ – NicoDean Feb 10 '15 at 15:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.