2
$\begingroup$

I want to plot something like the graph in the figure.

grapgh

I have some points (data) and each of them is associated to two different confidence intervals, at 90% (red) and 95% (blue). These intervals can be asymmetric, as you see in the picture.

I tried to use ErrorListPlot but I don't manage to plot only the x-errors and the results is a mess.

$\endgroup$
1
  • $\begingroup$ Please add data to work with and show what you tried so far. $\endgroup$
    – Yves Klett
    Commented Nov 27, 2016 at 18:27

1 Answer 1

6
$\begingroup$
Needs["ErrorBarPlots`"]

ErrorBar accepts two arguments:

plot0 = ErrorListPlot[{{{1, 1}, ErrorBar[0.3, 0]}}]

enter image description here

which each can be in form of a List to indicate assymetric confidence intervals:

plot1 = ErrorListPlot[{{{1, 1}, ErrorBar[{-0.5, 0.1}, 0]}}]

enter image description here

plot2 = ErrorListPlot[{{{1, 1}, ErrorBar[{-0.7, 0.3}, 0]}}, PlotStyle -> Red]

enter image description here

You can then just Show two plots together (mind the order):

Show[plot2, plot1]

enter image description here

or with a more appealing look by introducing an offset (credit: Bob Hanlon):

Show[plot1 /. {x_?NumericQ, y_?NumericQ} -> {x, y + 0.03}, 
     plot2 /. {x_?NumericQ, y_?NumericQ} -> {x, y - 0.03}]

enter image description here


As far as I know, ErrorListPlot isn't very flexible when it comes to styling the points and bars separately (see here and here for custom implementations). I'd combine it simply with a ListPlot:

plot1 = ErrorListPlot[{{{1, 1}, ErrorBar[{-0.5, 0.1}, 0]}}, 
  PlotStyle -> PointSize[0]]
plot2 = ErrorListPlot[{{{1, 1}, ErrorBar[{-0.7, 0.3}, 0]}}, 
  PlotStyle -> {Red, PointSize[0]}]

Show[plot2, plot1, 
 ListPlot[{{1, 1}}, PlotStyle -> {Black, PointSize[Large]}]]

enter image description here

$\endgroup$

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