5
$\begingroup$

I'm plotting a set of data with a constant uncertainty using ErrorListPlot. I would like to plot the error bars without the little horizontal caps that are on either end, but I'm a bit new to ErrorListPlot and don't know how.

I'm just plotting something simple as follows. 'data' is an array of form

{{{x,y},ErrorBar[sigma]},{...}}, 

where I am plotting x against y, with constant y uncertainty, sigma = 0.35. Note: the array was constructed elsewhere.

data = errplot4258;
Show[ErrorListPlot[data]]

plot

I think I'm meant to do something like

ErrorListPlot[data,ErrorBarFunction -> Function[{coords,errs},Line{{0,0} + coords + errs}]]

But, I don't really get what the 'coords' or 'errs' terms are doing. I can't find any explanation for how to use them to shape the error bars. Any help would be appreciated.

Again, what I'm after is to have vertical error bars with no caps on the end; just the vertical lines!

Thanks, JD,

$\endgroup$

2 Answers 2

6
$\begingroup$

If you look help for ErrorBarFunction, it gives you an example for rectangular region. Since you did not provide the data, i'll use the example from the help to illustrate.

First, lets plot the following example with default ErrorBarFunction

ErrorListPlot[{{{1, 1}, ErrorBar[0.2, 0.3]}, {{2, 2}, ErrorBar[0.2,0.3]}, {{3, 4}, 
ErrorBar[0.2, 0.5]}, {{4, 8}, ErrorBar[1, 2]}}, ErrorBarFunction -> Automatic]

Which gives

enter image description here

Modifying the ErrorBarFunction as below

ErrorListPlot[{{{1, 1}, ErrorBar[0.2, 0.3]}, {{2, 2}, 
   ErrorBar[0.2, 0.3]}, {{3, 4}, ErrorBar[0.2, 0.5]}, {{4, 8}, 
   ErrorBar[1, 2]}}, 
ErrorBarFunction -> Function[{coords, errs}, {(*vline*)Line[{coords - {0, errs[[2, 2]]}, 
   coords + {0, errs[[2, 2]]}}], 
   (*hline*)Line[{coords - {errs[[1, 1]], 0}, coords + {errs[[1, 1]], 0}}]}]]

gives

enter image description here

$\endgroup$
5
$\begingroup$

You can also post-process the output of ErrorListPlot to remove the "caps":

ClearAll[removeCaps]
removeCaps = # /. Line[x_, ___] /; Not[FreeQ[x, _Offset]] :> Sequence[] &;

Example:

Needs["ErrorBarPlots`"];
data = {{{1, 1}, ErrorBar[0.2, 0.5]}, {{2, 2}, ErrorBar[0, 1.5]},
   {{3, 4}, ErrorBar[.5, 0]}, {{4, 8}, ErrorBar[1, 2]}};

elp = ErrorListPlot[data, PlotStyle -> {PointSize[Large], Red}, 
   PlotRange -> All, PlotRangePadding -> 1, Frame -> True, 
   Axes -> False, ImageSize -> 350];

Row[{#, removeCaps @ #}] & @ elp

enter image description here

$\endgroup$

Your Answer

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

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