19

I've been using the shiny new legends in V9 for my plots. However, I usually increase the Frame/Axis Thickness and the plot Thickness and I would like the thickness of the legend line to match. There is a related question (Legend of a plot: how to increase the size of the line/marker?) asked about using the previous PlotLegends package.

See this simple example, modified from the documentation:

Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, 
  PlotLegends -> Automatic, 
  PlotStyle -> Thickness[0.005], 
  AxesStyle -> Thickness[0.005]]

Mathematica graphics

I've tried the obvious modification of the LineLegend LabelStyle, however, this just appears to modify the text and has no effect here:

Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, 
  PlotLegends -> LineLegend[Automatic, LabelStyle -> Thickness[0.5]], 
  PlotStyle -> Thickness[0.005], 
  AxesStyle -> Thickness[0.005]]

Mathematica graphics

I found that I could set Joined -> False and use a thicker line as a LegendMarker but it is never as long as the normal legend line no matter how long you make the line... (also note that to get a comparable thickness it has to be set two orders of magnitude higher)

Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, 
 PlotLegends -> 
  LineLegend[Automatic, Joined -> False, 
   LabelStyle -> Directive[FontFamily -> "Helvetica", Medium], 
   LegendMarkers -> 
    Graphics[{Thickness[0.5], Line[{{-2, 0}, {2, 0}}]}]], 
 PlotStyle -> Thickness[0.005], AxesStyle -> Thickness[0.005]]

Mathematica graphics

now make the line really long (no change):

Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, 
 PlotLegends -> 
  LineLegend[Automatic, Joined -> False, 
   LabelStyle -> Directive[FontFamily -> "Helvetica", Medium], 
   LegendMarkers -> 
    Graphics[{Thickness[0.5], Line[{{-100, 0}, {100, 0}}]}]], 
 PlotStyle -> Thickness[0.005], AxesStyle -> Thickness[0.005]]

Mathematica graphics

I've tried to look at the InputForm for the plots and for just a LineLegend but I can't figure out what exactly I need to replace to fix this.

s0rce
  • 9,632
  • 4
  • 45
  • 78
  • Note, the boxed 1 and 2 are placeholders that can be edited. Personally, I prefer "Expressions" to Automatic as it will display the equations used, for function plots, only, of course. – rcollyer Mar 15 '13 at 03:02
  • I think you're looking for LegendMarkerSize. See also: http://mathematica.stackexchange.com/q/19283/8 – Verbeia Mar 15 '13 at 04:08

4 Answers4

13

I find it useful to stick with AbsoluteThickness (and related) when using PlotLegends.

Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, PlotLegends -> Automatic, 
  PlotStyle -> AbsoluteThickness[2], AxesStyle -> AbsoluteThickness[2]]

enter image description here

chuy
  • 11,205
  • 28
  • 48
10

If you remove Joined->False it seems that you can get a better length for the given line thickness:

Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, 
PlotLegends -> 
LineLegend[Automatic, 
LabelStyle -> Directive[FontFamily -> "Helvetica", Medium], 
LegendMarkers -> 
Graphics[{Thickness[0.2], Line[{{-10, 0}, {10, 0}}]}]], 
PlotStyle -> Thickness[0.005], AxesStyle -> Thickness[0.005]]

thicker and longer lines

s0rce
  • 9,632
  • 4
  • 45
  • 78
Jonathan Shock
  • 3,015
  • 15
  • 24
9

As a last resort you can always adjust LineLegend manually:

stl[n_, thick_] := Thread[{ColorData[97, "ColorList"][[;; n]], AbsoluteThickness@thick}];
leg = LineLegend[Directive@@@stl[2, 10], Automatic];
Plot[{Sin[x], Cos[x]}, {x, 0, \[Pi]}, PlotLegends -> leg]

enter image description here

I'm quite surprised that one can't do it in more usual way..

funnyp0ny
  • 1,905
  • 14
  • 21
5
frame[legend_] :=Framed[legend, FrameStyle -> {Black, Thickness[1.]}, RoundingRadius -> 10, FrameMargins -> 2, Background -> White];
Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, PlotStyle -> {{Orange, AbsoluteThickness[3]}, {Blue, Dashed, AbsoluteThickness[3]}}, PlotLegends ->Placed[LineLegend[{Style["Experimental Results", 17], Style["Numeric Results", 17]}, LegendFunction -> frame], {1.1, 0.5}], ImageSize -> 500]

enter image description here

mrtydn
  • 123
  • 1
  • 2
  • 5