2

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.

corey979
  • 23,947
  • 7
  • 58
  • 101
apt45
  • 1,648
  • 9
  • 14

1 Answers1

6
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

corey979
  • 23,947
  • 7
  • 58
  • 101