0
$\begingroup$

How can I change the font size of the Legend? I have to plot 5 functions, and I already wrote the code, with the colors and so on.

But when I write the final code for the PlotLegends, that is

PlotLegends -> 
Placed[{Style["\[Nu] = 0", Black, 10], ["\[Nu]=0.25", Red, 
10],["\[Nu]=0.5", Green, 10] AND SO ON }, {0.2, 0.7}]

It doesn't work.

I want to change the plot legend size, in order to have a better plot.

$\endgroup$
  • 1
    $\begingroup$ You didn't give code other people can run, so try this: Plot[Table[ChebyshevT[k, x], {k, 1, 3}] // Evaluate, {x, -1, 1}, PlotLegends -> Placed[LineLegend[MapThread[Style, {{"k = 1", "k = 2", "k = 3"}, {Black, Red, Green}}], LabelStyle -> 10], {0.25, 0.65}]] $\endgroup$ – J. M. is away Sep 26 '18 at 14:07
  • $\begingroup$ @J.M.issomewhatokay. That works perfectly! Just one more question: how to change the font? Say I want to use Times New Roman, or Serif... $\endgroup$ – Henry Sep 26 '18 at 15:04
  • 1
    $\begingroup$ Just modify the LabelStyle setting: LabelStyle -> {10, FontFamily -> "Times New Roman"}. Please read the docs for LineLegend[], it's all there. $\endgroup$ – J. M. is away Sep 26 '18 at 15:29
2
$\begingroup$

LineLegend is the function that ultimately constructs the legend for Plot. It has a lot of options that can be modified to adjust the appearance of the legend. If you're trying to control the size, the most useful options are probably

  • LabelStyle: change the overall style for the labels, including font size
  • LegendMarkerSize: control how long the sample lines are
  • LegendMargins: control how much space is left around the legend
  • LegendLayout: switch from column to row

Here are some examples of each of these options being used:

{Framed[LineLegend[{Red, Green, Blue}, {"red", "green", "blue"}]],
 Framed[LineLegend[{Red, Green, Blue}, {"red", "green", "blue"}, 
   LabelStyle -> 10]],
 Framed[LineLegend[{Red, Green, Blue}, {"red", "green", "blue"}, 
   LegendMarkerSize -> 5]],
 Framed[LineLegend[{Red, Green, Blue}, {"red", "green", "blue"}, 
   LegendMargins -> 0]],
 Framed[LineLegend[{Red, Green, Blue}, {"red", "green", "blue"}, 
   LegendLayout -> "Row"]]}

enter image description here

Individually they may not be much smaller, but using them together can have a much bigger effect.

Framed[LineLegend[{Red, Green, Blue}, {"red", "green", "blue"},
    LabelStyle -> 10, LegendMarkerSize -> 5, LegendMargins -> 0]]

enter image description here

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