16
$\begingroup$

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., [email protected]], 
   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., [email protected]], 
       ImageSize -> Large,
       ErrorBarFunction -> {[email protected],Automatic}]
$\endgroup$

5 Answers 5

3
$\begingroup$

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

$\endgroup$
15
$\begingroup$

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 :> {[email protected], l} &)
 ]

enter image description here

$\endgroup$
7
  • $\begingroup$ Aaaa, very good. I think this s exactly what I was looking for. $\endgroup$
    – Ajasja
    Commented Jun 11, 2013 at 20:27
  • $\begingroup$ I have an "industrial strength" solution for creating your own plot marker function, but this was by far easier. $\endgroup$
    – rcollyer
    Commented Jun 11, 2013 at 20:28
  • $\begingroup$ 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:) $\endgroup$
    – Ajasja
    Commented Jun 11, 2013 at 20:33
  • $\begingroup$ It's not, but it does require a bit more code ... I'll post it tonight. Time to go wake the munchkin from nap. $\endgroup$
    – rcollyer
    Commented Jun 11, 2013 at 20:34
  • $\begingroup$ @Ajasja I finally posted it, but under a different question. :P $\endgroup$
    – rcollyer
    Commented Feb 19, 2014 at 21:40
13
$\begingroup$

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

$\endgroup$
5
  • 1
    $\begingroup$ Pretty, +1. Which solution is it based on? $\endgroup$
    – rcollyer
    Commented Jun 11, 2013 at 20:27
  • $\begingroup$ @rcollyer belisarius's answer (added link above). $\endgroup$
    – s0rce
    Commented Jun 11, 2013 at 20:56
  • $\begingroup$ Thanks, I should've been able to pick that out. $\endgroup$
    – rcollyer
    Commented Jun 11, 2013 at 20:56
  • 1
    $\begingroup$ 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). $\endgroup$
    – Ajasja
    Commented Jun 12, 2013 at 7:48
  • $\begingroup$ @Ajasja My mistake, thanks for the fixing the code. $\endgroup$
    – s0rce
    Commented Jun 12, 2013 at 16:38
7
$\begingroup$

Points are stylled with PlotStyle, Lines with ReplaceAll:

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

(it was Sequence[[email protected],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

$\endgroup$
4
  • $\begingroup$ Thanks, this was my first idea. But it's not good enough. Also you have to specify the colors twice... $\endgroup$
    – Ajasja
    Commented Jun 11, 2013 at 20:22
  • $\begingroup$ @Ajasja I've deleted Epilog version. This is better.. I think :) $\endgroup$
    – Kuba
    Commented Jun 11, 2013 at 20:39
  • 2
    $\begingroup$ While I gave you a +1, using Sequence[[email protected], x] can lead to unintended consequences. It is better to use {[email protected], x} so the format only applies to x. $\endgroup$
    – rcollyer
    Commented Jun 11, 2013 at 20:55
  • $\begingroup$ @rcollyer You are right, I was trying to be fancy and I forgot about basics. :) $\endgroup$
    – Kuba
    Commented Jun 11, 2013 at 21:03
3
$\begingroup$

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
 ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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