15
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – rcollyer Mar 15 '13 at 3:02
  • $\begingroup$ I think you're looking for LegendMarkerSize. See also: mathematica.stackexchange.com/q/19283/8 $\endgroup$ – Verbeia Mar 15 '13 at 4:08
11
$\begingroup$

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

$\endgroup$
8
$\begingroup$

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

$\endgroup$
6
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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