2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Do you also need additional Ticks for the second plot. So there should be double 10 and double 20? That is what is on your image, just want to confirm. $\endgroup$ – Kuba Oct 25 '14 at 15:48
  • $\begingroup$ @Kuba yes, this would be great $\endgroup$ – spore234 Oct 25 '14 at 15:58
4
$\begingroup$
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

$\endgroup$
  • $\begingroup$ perfect, thanks. I didn't know you can shift the plots. $\endgroup$ – spore234 Oct 25 '14 at 18:02
3
$\begingroup$

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

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

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

$\endgroup$
  • $\begingroup$ no, the plots should be next to each other $\endgroup$ – spore234 Oct 25 '14 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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