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$
2
  • $\begingroup$ This is in V9; the lines in the legend are thicker by default starting in V10.0. $\endgroup$ Dec 9, 2015 at 1:17
  • $\begingroup$ Yes I have version 9 :/ $\endgroup$
    – Enrico M.
    Dec 9, 2015 at 1:36

2 Answers 2

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$
2
  • $\begingroup$ Oh this is awesome, it make the legend colored itself! Thank you!! $\endgroup$
    – Enrico M.
    Dec 8, 2015 at 23:36
  • $\begingroup$ Excellent idea, +1 $\endgroup$
    – eldo
    Dec 8, 2015 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
  • 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$
    – Enrico M.
    Dec 8, 2015 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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