ErrorListPlot Legend with Markers

2

0

I'm trying for some days now to integrate markers in my legend. I have a ErrorListPlot with markers and a legend but difficulties to realize the markers in the legend as well. Thanks a lot for your answers in advance! Here is my Mathematica Code:

Needs["ErrorBarPlots`"];
Needs["PlotLegends`"];

K = {{{4, 14.5566}, ErrorBar[0.2789/2]}, {{19, 15.46581}, 
    ErrorBar[0.27794/2]}, {{26, 17.76820}, ErrorBar[0.33368/2]}};

F = {{{1, 12.634}, ErrorBar[0.216414/2]}, {{11, 13.84994}, 
    ErrorBar[0.402/2]}, {{18, 15.622}, ErrorBar[0.26659/2]}};

ClearAll[simpleLegend]
simpleLegend[legendItems__, pos_] := 
 Module[{legendLine, offset, legend}, 
  offset = Module[{s, o, insetpts = 10}, 
    s = pos /. {Left -> 0, Right -> 1, Bottom -> 0, Top -> 1};
    o = insetpts pos /. {Left -> 1, Right -> -1, Bottom -> 1, Top -> -1};
    Offset[o, Scaled[s]]];
  legendLine[{lbl_, 
     lineStyle_}] := {Graphics[{lineStyle, Line[{{0, 0.5}, {1, 0.5}}]}, 
     ImageSize -> {20, 10}, AspectRatio -> 0.5], 
    Style[lbl, FontFamily -> "Arial", Bold, FontSize -> 12, 
     TextAlignment -> Left, LineBreakWithin -> False]};
  legend = GraphicsGrid[legendLine /@ legendItems, Alignment -> Left];
  Graphics@Inset[legend, offset, pos]]; PlotMarkers -> {{\[FilledUpTriangle], 
   18}, {\[FilledDownTriangle], 18}};

labels = {"928", "927"};
styles = {Directive[{RGBColor[0.639216, 0.329412, 0.772549]}], 
   Directive[{Blue}]};
plot = ErrorListPlot[{F, K}, PlotStyle -> styles,
   FrameTicksStyle -> Directive[Thick, FontFamily -> "Arial", 12, Bold],
   PlotMarkers -> {{\[FilledUpTriangle], 18}, {\[FilledDownTriangle], 18}},
   Joined -> True,
   PlotRange -> {{0, 50}, {12, 18}}, 
   FrameLabel -> {Style["Alter / Tage", 12, Bold, FontFamily -> "Arial"],
     Style["Absorption / dB/cm", 12, Bold, FontFamily -> "Arial"], None, 
     None}, Frame -> True];
Show[plot, simpleLegend[Thread@{labels, styles}, {Right, Top}]]

Mathematica graphics

edit: for clearing my probelem: I'd like to have the same markers as in the plot in the legend lines as well..

jery

Posted 2013-04-02T12:44:48.820

Reputation: 23

Please read the FAQ and highlight your code appropriately. Also, leave out the In[*] Out[*] stuff, – Ajasja – 2013-04-02T12:48:37.760

I'm not understanding your "difficulties" clearly. Could you please explicit them? – Dr. belisarius – 2013-04-02T13:04:53.377

Take a look at this solution to a very similar question.

– rcollyer – 2013-04-02T13:59:27.903

Thanks, that would help, but here they are using the same items as markers for all the lines. is it really the only way to name them one by one? (means, do i really have to define each legend color, line, character for the specific plotline?) – jery – 2013-04-03T12:59:41.763

Answers

1

This answer may not help you... In the current version of Mathematica (version 9), you can use LineLegend:

ErrorListPlot[{F, K},
...
PlotLegends -> Placed[LineLegend[labels], {Right, Center}]
]

legend

If I try to run your code, I see this message:

error

cormullion

Posted 2013-04-02T12:44:48.820

Reputation: 23 565

Of course, no error is shown in V8 :) – Dr. belisarius – 2013-04-02T13:35:09.713

@belisarius I hope you never become obsolete... :) – cormullion – 2013-04-02T13:36:32.067

That word applies to a broad range of situations. I somehow guess some of them already occurred, while others may take some time yet – Dr. belisarius – 2013-04-02T13:38:59.873

I cannot use PlotLegends with ErrorListPlot in Mathematica 8... – jery – 2013-04-02T13:47:03.317

@jery No problem. At least now people will know that you aren't avoiding an obvious solution. (Your question could perhaps benefit from having version-specific requirements added!) – cormullion – 2013-04-02T13:52:50.487