Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

1.- How to put DASHED lines in the Legend? 2.- How to give Style to {20,Bold} to all "Expressions in Legend?

enter image description here

(I use LegendMarkSize for make lines wider than default fine style )

Plot[{{E^(x/(1/4)), E^(x/(1/3)), E^(x/(1/2))}, {E^(x/1), E^(x/2), 
   E^(x/3), E^(x/4)}}, {x, -5, 0.2}, 
 PlotStyle -> {{Dashing[0.024], Thickness[0.01]}, {Dashing[0.024], 
    Thickness[0.01]}, {Dashing[0.024], Thickness[0.01]}, 
   Thickness[0.01], Thickness[0.01], Thickness[0.01], 
   Thickness[0.01]}, 
 PlotLegends -> 
  SwatchLegend[ "Expressions", LegendMarkerSize -> {39, 6}], 
 PlotRange -> {{-5, 0.15}, {0, 1.15}}]
share|improve this question

2 Answers 2

up vote 5 down vote accepted

The style for labels in a legend is determined by the option LabelStyle. To get the legend markers to match the style of the plot without rescaling, one approach is to use AbsoluteDashing and AbsoluteThickness to style the plot lines.

With[{d = AbsoluteDashing[8], t = AbsoluteThickness[4]}, 
 Plot[{E^(4 x), E^(3 x), E^(2 x), E^x, E^(x/2), E^(x/3), E^(x/4)}, {x, -5, 0.2},
  PlotStyle -> {{d, t}, {d, t}, {d, t}, t, t, t, t},
  PlotRange -> {{-5, 0.15}, {0, 1.15}},
  PlotLegends -> LineLegend["Expressions",
    LabelStyle -> {Bold, 20}, LegendMarkerSize -> {40, 10}]]]

enter image description here

share|improve this answer
    
Thank you, your solution is perfect!. only have to add... {Bold,20} to maintain the axis numbers bigger. Thank you –  Mika Ike May 3 at 15:42

AbsoluteDash and AbsoluteThickness are helpful in this. In the following I have arbitrarily chosen colours for illustrative purposes (so you can change as desired):

leg = {{Red, AbsoluteDashing[5], AbsoluteThickness[2]}, {Green, 
    AbsoluteDashing[5], AbsoluteThickness[2]}, {Blue, 
    AbsoluteDashing[5], AbsoluteThickness[2]}, {Red, 
    AbsoluteThickness[2]}, {Green, AbsoluteThickness[2]}, {Blue, 
    AbsoluteThickness[2]}, {Purple, AbsoluteThickness[2]}};
fns = {{E^(x/(1/4)), E^(x/(1/3)), E^(x/(1/2))}, {E^(x/1), E^(x/2), 
    E^(x/3), E^(x/4)}};
Plot[fns, {x, -5, 0.2}, PlotRange -> {{-5, 0.15}, {0, 1.15}}, 
 PlotStyle -> leg, 
 PlotLegends -> LineLegend[Directive @@@ leg, Flatten@fns]]

This yields:

enter image description here

share|improve this answer
    
You´re answer is TOO an SOLUTION FOR ME. I chosed the other because was posted before. –  Mika Ike May 3 at 13:41
    
@MikaIke thanks...that's fine I think Simon Woods is neater (note he flattened your list of expressions which were nested in your code: I flattened in my legend) –  ubpdqn May 3 at 13:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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