16

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}]
kglr
  • 394,356
  • 18
  • 477
  • 896
Ajasja
  • 13,634
  • 2
  • 46
  • 104

5 Answers5

15

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

rcollyer
  • 33,976
  • 7
  • 92
  • 191
  • 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 '14 at 21:40
  • Err...I found no thing like "ebarfun" after searching document, however,Names["ErrorBarPlotsPrivate*"] (there is a "`" eaten)do give many this kinds of all-lowercase-letter function/var. I wonder how did you find these mysterious magic function and their usage? – Harry Dec 18 '14 at 11:57
  • @Harry I cheated. I read the package file. But, you can also use ?ErrorBarPlots`*`* to show all the internal symbols in the package. – rcollyer Dec 18 '14 at 12:19
13

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

s0rce
  • 9,632
  • 4
  • 45
  • 78
7

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

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 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
3

You can use the sub-option "LineOpacity" in PlotStyle:

ErrorListPlot[data, PlotStyle -> Directive[Thick, PointSize[Large], "LineOpacity" -> 0.2]]

enter image description here

It also works in version 9.0:

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
3

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
 ]
Ajasja
  • 13,634
  • 2
  • 46
  • 104