2

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..

rcollyer
  • 33,976
  • 7
  • 92
  • 191
jery
  • 23
  • 1
  • 4
  • Please read the FAQ and highlight your code appropriately. Also, leave out the In[*] Out[*] stuff, – Ajasja Apr 02 '13 at 12:48
  • I'm not understanding your "difficulties" clearly. Could you please explicit them? – Dr. belisarius Apr 02 '13 at 13:04
  • Take a look at this solution to a very similar question. – rcollyer Apr 02 '13 at 13:59
  • 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 Apr 03 '13 at 12:59

1 Answers1

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
  • 24,243
  • 4
  • 64
  • 133