2

I made two ErrorListPlots

Needs["ErrorBarPlots`"]
myplot = ErrorListPlot[{{{20, 0.75}, 
 ErrorBar[{0.5 - 0.75, 0.9 - 0.75}]}, {{10, 0.7}, 
 ErrorBar[{0.5 - 0.7, 0.97 - 0.7}]}}, 
 FrameTicks -> {{10, 20}, Automatic}];
Show[myplot, PlotRange -> All, Frame -> True]

enter image description here

then I collected some other data and generated a second plot:

myplot2 = 
 ErrorListPlot[{{{20, 0.85}, 
 ErrorBar[{0.5 - 0.85, 0.9 - 0.85}]}, {{10, 0.8}, 
 ErrorBar[{0.6 - 0.8, 0.91 - 0.8}]}}, 
 FrameTicks -> {{10, 20}, Automatic}];

I now want a single plot where I compare both results. It should look like this:

enter image description here

Please excuse my shitty drawing. The myplot2 bars should be right to the myplot Bars (unlike in the picture) and have a different color. The 10 and 20 values should be a bit separated. How can I do that?

My only idea is to copy and paste the myplot2 data in the myplot plot and change the axis labels. But this does not address separation and color.

spore234
  • 601
  • 6
  • 10

3 Answers3

4
Needs["ErrorBarPlots`"]

myplot = ErrorListPlot[{
    {{20, 0.75}, ErrorBar[{0.5 - 0.75, 0.9 - 0.75}]}, {{10, 0.7}, 
     ErrorBar[{0.5 - 0.7, 0.97 - 0.7}]}}];

myplot2 = ErrorListPlot[{
    {{20, 0.85}, ErrorBar[{0.5 - 0.85, 0.9 - 0.85}]},
    {{10, 0.8}, ErrorBar[{0.6 - 0.8, 0.91 - 0.8}]}},
   PlotStyle -> Red];

Show[
 myplot /. {x_?NumericQ, y_?NumericQ} -> {x - 0.15, y},
 myplot2 /. {x_?NumericQ, y_?NumericQ} -> {x + 0.15, y},
 Frame -> True, Axes -> False,
 FrameTicks -> {{10, 20}, Automatic},
 PlotRange -> {{9.5, 20.5}, Automatic}]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
3

Not the fastest but the most general way is to learn how to use Overlay, very useful function.

With[{
  opt = Sequence[PlotRange -> {.4, 1}, FrameTicks -> {{10, 20}, Automatic}, 
                 BaseStyle -> AbsolutePointSize@10]
  },
 myplot = ErrorListPlot[{{{20, 0.75}, ErrorBar[{0.5 - 0.75, 0.9 - 0.75}]},
           {{10, 0.7},  ErrorBar[{0.5 - 0.7, 0.97 - 0.7}]}},
          ImageSize -> 500 {1, 1/GoldenRatio}, AspectRatio -> 1/GoldenRatio, 
          Frame -> True, opt];

 myplot2 =  ErrorListPlot[{{{20, 0.85}, ErrorBar[{0.5 - 0.85, 0.9 - 0.85}]}, {{10, 0.8}, 
             ErrorBar[{0.6 - 0.8, 0.91 - 0.8}]}}, 
            ImageSize -> 500 {1, 1}/GoldenRatio, AspectRatio -> 1, 
            Frame -> {True, False}, opt];


 Overlay[{myplot, myplot2}, Alignment -> Center]

 ]

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • thanks, this is looking good. But how would I manage more than two sections, e.g. 10, 20, 30, 50, 100. – spore234 Oct 25 '14 at 16:29
  • @spore234 it depends of details but maybe Bob`s answer is better suited for that purpose. – Kuba Oct 25 '14 at 16:33
0

try this if it help:

myplot = ErrorListPlot[{{{20, 0.75},
     ErrorBar[{0.5 - 0.75, 0.9 - 0.75}]}, {{10, 0.7},
     ErrorBar[{0.5 - 0.7, 0.97 - 0.7}]}}, 
   FrameTicks -> {{10, 20}, Automatic}, PlotRange -> All, 
   Frame -> True, PlotStyle -> Black, PlotRangePadding -> 1];
myplot2 = 
  ErrorListPlot[{{{20, 0.85}, 
     ErrorBar[{0.5 - 0.85, 0.9 - 0.85}]}, {{10, 0.8}, 
     ErrorBar[{0.6 - 0.8, 0.91 - 0.8}]}}, 
   FrameTicks -> {{10, 20}, Automatic}, Frame -> True, 
   PlotStyle -> {Thickness[0.01], Red, PointSize[0.02]}, 
   PlotRangePadding -> 0.5];
Show[myplot2, myplot]

enter image description here

Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78