# Does PlotLegend lie in a figure?

I wonder if PlotLegends is part of a figure. Indeed in the code

Show[
Plot[Sin[x], {x, 0, 2 π}, PlotStyle -> Black,
PlotLegends -> LineLegend[{Black}, {"Sin"}]],
Plot[Cos[x], {x, 0, 2 π}, PlotStyle -> Red,
PlotLegends -> LineLegend[{Red}, {"Cos"}]],
BaseStyle -> {FontSize -> 15, FontFamily -> "LM Roman 10"}
]


it does not seem to be affected by BaseStyle and not shown in the exported figure.

Is that a bug or am I missing something?

• The short answer is no. If you make a plot with legends and type Head[%], it will say Legended instead of Graphics or Graphics3D etc. – Jens Jan 24 '16 at 19:12

The answer to your question is, it depends. If the legend is placed inside the area of the graphic, then the graphic, including the legend, can be highlighted and saved by right-clicking and choosing Save Graphics As...

The code used to produce this graphic is

Plot[{Sin[x], Cos[x]}, {x, 0, 2 π}, PlotStyle -> {Black, Red},
PlotLegends -> Placed[LineLegend[{Sin, Cos},
LabelStyle -> {FontFamily -> "Magneto"}], {.6, .8}],
BaseStyle -> {FontSize -> 15, FontFamily -> "Goudy Stout"}]


Note that the LineLegend uses the FontSize from the plot BaseStyle, but not the FontFamily. Consequently, it must be specified separately, as shown. I used two distinctive fonts, so that their difference would be obvious. (I do not have the LM Roman 10 font.) More generally, LineLegend has many options that can be used to create stylized legends.

• Actually, you're not using "LM Roman 10" neither for the axes nor for the legends. Do you have that font or your solution is not working? – Fabio Jan 24 '16 at 13:51
• @Fabio Good point. I do not have that font. Also, the legend is ignoring the FontFamily in Baseline, even though it is not ignoring the FontSize. I shall give this more thought. – bbgodfrey Jan 24 '16 at 14:19
• @Fabio To specify the legend font, it appears necessary to use PlotLegends -> Placed[LineLegend[{Sin5, Cos}, LabelStyle -> {FontFamily -> "Magneto"}], {.6, .8}] I used a distinctive font here, so that I would be sure that it changed. I shall edit it into my answer soon. Thanks for catching this issue. – bbgodfrey Jan 24 '16 at 14:29
• I had the same conclusion, but still I' still convinced that BaseStyle should be inherited by all of the text in a plot. – Fabio Jan 24 '16 at 14:49
• @Fabio Version 10 introduced a number of formatting bugs in PlotLegends. Perhaps, not all of them have been corrected. See, for instance, my earlier question 55150. – bbgodfrey Jan 24 '16 at 14:53

I always had problems with that. I use Export and the expression in order to get the legend in the exported figure.

plot = Show[
Plot[Sin[x], {x, 0, 2 π}, PlotStyle -> Black,
PlotLegends -> LineLegend[{Black}, {"Sin"}]],
Plot[Cos[x], {x, 0, 2 π}, PlotStyle -> Red,
PlotLegends -> LineLegend[{Red}, {"Cos"}]],
BaseStyle -> {FontSize -> 15, FontFamily -> "LM Roman 10"}]

Export[NotebookDirectory[] <> "fig.png", plot]