4
$\begingroup$

I want to plot two (or more) functions, inserting in the plot itself the legend that will clarify me what are those plotted functions. I know this basic standard command lines:

 Plot[{Log[x], Log[Sin[x]]}, {x, -1, 23}, 
   PlotLegends -> Placed[{Log[x],  Log[Sin[x]]}, {0.8, 0.8}], 
   PlotStyle -> {{Red, Thickness[0.004]}, {Blue, Thickness[0.004]}}, 
   LabelStyle -> {FontSize -> 11}]

Which works quite good because the output is

enter image description here

But my problem is that it's really difficult to see the associated colors line in the legend. How can I solve this problem?

If someone knew a solution, or a different (better) code to make those things work better, I would be so thankful!

$\endgroup$
  • $\begingroup$ This is in V9; the lines in the legend are thicker by default starting in V10.0. $\endgroup$ – Brett Champion Dec 9 '15 at 1:17
  • $\begingroup$ Yes I have version 9 :/ $\endgroup$ – Henry Dec 9 '15 at 1:36
8
$\begingroup$

Code:

Plot[
 {Log[x], Log[Sin[x]]}, {x, -1, 23},
 PlotLegends -> 
  Placed[{Style[Log[x], Red], Style[Log[Sin[x]], Blue]}, {0.8, 0.8}],
 PlotStyle -> {{Red, Thickness[0.004]}, {Blue, Thickness[0.004]}},
 LabelStyle -> {FontSize -> 11}]

Output:

Output 1

Alternative:

Plot[
 {Log[x], Log[Sin[x]]}, {x, -1, 23},
 PlotLegends -> 
  Placed[SwatchLegend[{Red, Blue}, {Style["Log[x]", Red, Bold], 
     Style["Log[Sin[x]]", Blue, Bold]}, 
    LegendMarkerSize -> {30, 10}], {0.8, 0.8}],
 PlotStyle -> {{Red, Thickness[0.004]}, {Blue, Thickness[0.004]}},
 LabelStyle -> {FontSize -> 11}]

Output:

Output 2

$\endgroup$
  • $\begingroup$ Oh this is awesome, it make the legend colored itself! Thank you!! $\endgroup$ – Henry Dec 8 '15 at 23:36
  • $\begingroup$ Excellent idea, +1 $\endgroup$ – eldo Dec 8 '15 at 23:38
5
$\begingroup$
Plot[{Log[x], Log[Sin[x]]}, {x, -1, 23},
 PlotLegends -> Placed[LineLegend["Expressions"], {0.8, 0.8}],
 PlotStyle -> {{Red, Thickness[0.004]}, {Blue, Thickness[0.004]}},
 LabelStyle -> {FontSize -> 11}]

enter image description here

Or, if you want to frame the legend

Plot[{Log[x], Log[Sin[x]]}, {x, -1, 23},
 PlotLegends -> 
  Placed[LineLegend["Expressions", LegendFunction -> "Frame"], {0.8, 0.8}],
 PlotStyle -> {{Red, Thickness[0.004]}, {Blue, Thickness[0.004]}},
 LabelStyle -> {FontSize -> 11}]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ This is awesome too!! Thank you guys, I bet there are tricks that I still have to know! Today I added a 0.001% more to my M. Knowledge :D $\endgroup$ – Henry Dec 8 '15 at 23:37

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.