2
$\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$
3
  • 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$ Commented Sep 26, 2018 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$ Commented Sep 26, 2018 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$ Commented Sep 26, 2018 at 15:29

1 Answer 1

4
$\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$
1
  • $\begingroup$ What to do if I don't want to change the overall label style? I only want to change the label size of the legends... $\endgroup$ Commented Jul 9, 2024 at 17:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.