Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to plot the error bars of ErrorListPlot with a different style than the points. I know of ErrorBarFunction, but then I have to recreate the automatic ErrorBarFunction...

Here is my current butt ugly hack (I draw the plot twice):

data = Table[{x, f[x], RandomReal[]}, {f, {Exp[2 #] &, Exp}}, {x, -5, 2, 0.2}];
Needs["ErrorBarPlots`"]

Show@{ErrorListPlot[data, 
   PlotStyle -> Directive[Thick, PointSize -> 0., Opacity@0.5], 
   ImageSize -> Large],
  ListPlot[data[[All, All, {1, 2}]], 
   PlotStyle -> Directive[Thick, PointSize -> 0.015], 
   ImageSize -> Large]
  }

example plot

What is a more elegant way of doing this?

Something like:

ErrorListPlot[data, 
       PlotStyle -> Directive[Thick, PointSize -> 0., Opacity@0.5], 
       ImageSize -> Large,
       ErrorBarFunction -> {Opacity@0.5,Automatic}]
share|improve this question
add comment

4 Answers

up vote 8 down vote accepted

You do not have to re-implement anything, just use a little chicanery:

ErrorListPlot[
 data,
 PlotStyle -> Directive[Thick, PointSize -> 0.015],
 ImageSize -> Large,
 PlotMarkers -> Automatic,
 ErrorBarFunction -> (ErrorBarPlots`Private`ebarfun[##] /. l_Line :> {Opacity@0.5, l} &)
 ]

enter image description here

share|improve this answer
    
Aaaa, very good. I think this s exactly what I was looking for. –  Ajasja Jun 11 '13 at 20:27
    
I have an "industrial strength" solution for creating your own plot marker function, but this was by far easier. –  rcollyer Jun 11 '13 at 20:28
    
Hmm, now you have my curiosity. Care to post the "industrial strength" solution as a separate answer? Assuming it is not an industrial secret, of course:) –  Ajasja Jun 11 '13 at 20:33
    
It's not, but it does require a bit more code ... I'll post it tonight. Time to go wake the munchkin from nap. –  rcollyer Jun 11 '13 at 20:34
    
@Ajasja I finally posted it, but under a different question. :P –  rcollyer Feb 19 at 21:40
add comment

Here is an alternative you might like based on an answer I got to a previous question of mine: Plotting Error Bars on a Log Scale

ClearAll[ePlot, ePlotFunc, plusMinusMean];
plusMinusMean[a_, b_] := {a + b, a - b, a};
ePlot[plotFun_, dataX_, plusMinList_, color_] := Block[{f},
  f[y_] := Transpose[{dataX, y}];
  plotFun[{
    f[plusMinList[[All, 1]]], f[plusMinList[[All, 2]]], 
    f[plusMinList[[All, 3]]]}, Filling -> {1 -> {2}}, 
   Joined -> {True, True, True}, 
   PlotStyle -> {Opacity[0], Opacity[0], Darker@color}, 
   PlotMarkers -> {Graphics@{Disk[]}, 0.03}, 
   FillingStyle -> Directive[Opacity[0.2], color], Frame -> True, 
   Axes -> False]]


ePlotFunc[data_, color_] := 
 Module[{dataY, dataX, errorY, plusMinList}, 
  dataY = data[[All, 2]];
  dataX = data[[All, 1]];
  errorY = data[[All, 3]];
  plusMinList = Thread[plusMinusMean[dataY, errorY]];
  ePlot[ListPlot, dataX, plusMinList, color]]

colors = {Hue[0.67, 0.6, 0.6], Hue[0.85, 0.6, 0.6]};

data = Table[{x, f[x], RandomReal[]}, {f, {Exp[2 #] &, Exp}}, {x, -5, 
    2, 0.2}];

Show@MapThread[ePlotFunc, {data, colors}]

example1

I hope you might be able to adapt this to your needs, see another example:

example2

share|improve this answer
1  
Pretty, +1. Which solution is it based on? –  rcollyer Jun 11 '13 at 20:27
    
@rcollyer belisarius's answer (added link above). –  s0rce Jun 11 '13 at 20:56
    
Thanks, I should've been able to pick that out. –  rcollyer Jun 11 '13 at 20:56
1  
Your original code was not working (you've been a bit sloppy and forgot to define PlusMinus and f). I've fixed it now (with non conflicting names). –  Ajasja Jun 12 '13 at 7:48
    
@Ajasja My mistake, thanks for the fixing the code. –  s0rce Jun 12 '13 at 16:38
add comment

Points are stylled with PlotStyle, Lines with ReplaceAll:

ErrorListPlot[data,
  PlotStyle -> Directive[Thick, PointSize -> 0.01], ImageSize -> Large
  ] /. x_Line :> {Opacity@.5, x}   

(it was Sequence[Opacity@.5,x] before rcollyer comment)

It is not allways so short, in case of more objects in Plot/Show etc. one has to specify pattern more carefully.

enter image description here

share|improve this answer
    
Thanks, this was my first idea. But it's not good enough. Also you have to specify the colors twice... –  Ajasja Jun 11 '13 at 20:22
    
@Ajasja I've deleted Epilog version. This is better.. I think :) –  Kuba Jun 11 '13 at 20:39
2  
While I gave you a +1, using Sequence[Opacity@.5, x] can lead to unintended consequences. It is better to use {Opacity@.5, x} so the format only applies to x. –  rcollyer Jun 11 '13 at 20:55
    
@rcollyer You are right, I was trying to be fancy and I forgot about basics. :) –  Kuba Jun 11 '13 at 21:03
    
+1 This is how I'll do it. –  Silvia Jun 12 '13 at 4:11
add comment

LevelScheme almost works, but outlines the plot markers with the same transparent fuzzy line, making the whole plot fuzzy.

Example image

Needs["LevelScheme`"]

dataScheme = data /. {x_, y_, e_} :> {x, ErrorValue[y, e]};

Figure[
 {
  Table[{
    SetOptions[DataLine, Color -> ColorData[1][i]],
    SetOptions[DataSymbol, SymbolShape -> "Circle", 
     FillColor -> ColorData[1][i], Color -> ColorData[1][i], 
     SymbolSize -> 6, Thickness -> 3, LineOpacity -> 0.5],

    DataPlot[
     dataScheme[[i]], Tag -> set[i]
     ]}
   , {i, 2}],

  DataLegend[{0.1, 0.95}, {{set[1], "Data"}, {set[2], "Data2"}}, 
   Length -> 10, Gap -> 5, FontSize -> 15, FontFamily -> "Arial"]

  },
 PlotRange -> {{-5, 2}, {-1, 10}}, ImageSize -> 72*{6, 3},
 Frame -> True
 ]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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