MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Error bars

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118664] Re: Error bars
  • From: Robert Rosenbaum <robertr at math.uh.edu>
  • Date: Fri, 6 May 2011 07:24:12 -0400 (EDT)

No problem Judy.

I might as well add some code I had written for myself a while back, in case you or anyone else finds it useful.
I always thought that the vertical lines on Mathematica's default error bars were too short, so I wrote my own ErrorBarFunction:

ebarrad = .5;
ebarthickness=.003;
ptsize=.025;
ebar =
  Function[{coords, errs}, {Thickness -> ebarthickness,
    Line[{coords + {-ebarrad, errs[[2, 1]]},
      coords + {ebarrad, errs[[2, 1]]}}],
    Line[{coords + {-ebarrad, errs[[2, 2]]},
      coords + {ebarrad, errs[[2, 2]]}}],
    Line[{coords + {0, errs[[2, 1]]}, coords + {0, errs[[2, 2]]}}],
    PointSize -> ptsize,
    Point[{coords}]}];


Just add "ErrorBarFunction->ebar" in your ErrorListPlot command.  You'll have to tweak the ebarrad parameter depending on the scale of your axes.  Using a Scaled size would probably be better, but I couldn't get it to work.


Best,
Robert



On May 5, 2011, at 4:26 AM, Judy Price wrote:

> Thanks, Robert, for the code. When I sent the data, I had forgotten to
> transpose a matrix, so my means are off.
>
> -----Original Message-----
> From: Robert Rosenbaum [mailto:robertr at math.uh.edu]
> Sent: Thursday, May 05, 2011 12:51 AM
> To: Judy Price
> Cc: mathgroup at smc.vnet.net
> Subject: [mg118645] Re: [mg118574] Error bars
>
> It's not the neatest solution and you'll need to tweak the aesthetics if you
> want to use it for a publication (see esp. ErrorBarFunction), but the code
> below should get you started.  BTW, the data you sent looks to be a bit off:
> there are a different number of means than intervals and the means do not
> all lie in their respective intervals.  Here's the code:
>
>
> Needs["ErrorBarPlots`"]
>
> means = {79.2834, 74.4719, 73.8007, 73.5467, 72.2965, 76.136, 75.1637,
>    74.341, 75.7873, 75.997, 73.6585, 75.1196, 76.3168, 73.8244,
>   75.4527, 76.4404, 75.0104, 76.5596, 76.2118, 75.8198};
> (*,72.9094,75.9392,77.5203,73.8933};*)
>
> intervals = {{71.5152, 75.6588}, {71.1603, 75.3777}, {72.2091,
>    76.9714}, {72.4496, 77.0188}, {74.7051, 78.4491}, {72.1719,
>    76.8556}, {72.2981, 77.7783}, {72.5936, 76.9063}, {74.3673,
>    78.4631}, {73.9854, 78.8609}, {74.6407, 77.7396}, {73.9558,
>    77.9133}, {72.2582, 76.3498}, {73.2699, 78.5874}, {71.4071,
>    77.1258}, {75.7951, 80.7734}, {74.3078, 78.3051}, {71.2209,
>    76.5365}, {70.7587, 76.3733}, {73.8667, 78.1864}};
>
> errs = intervals - means;
>
> n = Length[means];
>
> Show[{
>  BarChart[means, BarSpacing -> None],
>  ErrorListPlot[
>   Table[{{i - 1/2, means[[i]]}, ErrorBar[errs[[i]]]}, {i, 1, n}],
>   PlotStyle -> {Thick, PointSize[.02]}]
>  }]
>
>
>







  • Prev by Date: Looking for a notebook-aware Unify or Diff to compare notebook differences
  • Next by Date: Import - a cautionary tale
  • Previous by thread: Re: Error bars
  • Next by thread: RuleDelayed and Integration