2

Possible Duplicate:
Setting the default font for PlotLegends

Using version 9

The option setting for LabelStyle in plots (I've tried this in Plot[], DateListPlot[], and ListLinePlot[]) doesn't appear to affect PlotLegends[] at least the way I've tried it:

Plot[{Sin[x], Cos[x]}, {x, 0, 10}, 
 LabelStyle -> (FontFamily -> "Helvetica Neue"), 
 PlotLegends -> {"Sin", "Cos"}]

Plot[{Sin[x], Cos[x]}, {x, 0, 10}, 
 LabelStyle -> (FontFamily -> "Helvetica Neue"), 
 PlotLegends -> {"Sin", "Cos", LabelStyle -> (FontFamily -> "Helvetica Neue")}]

Both sets of code give the exact (to an eye) output:

enter image description here

Note the legend font remains in some default (TimesNewRoman) setting, where everything else in the plot properly goes to "Helvetica Neue".

I've also tried wrapping Style[] around each of the legend names to no avail.

Any thoughts on how to do this or work around it?


I stumbled upon a workaround, but it doesn't seem very elegant to me so I remain open to other solutions:

Plot[{Sin[x], Cos[x]}, {x, 0, 10}, 
 LabelStyle -> (FontFamily -> "Helvetica Neue"), 
 PlotLegends -> 
  SwatchLegend[{"Sin", 
    "Cos"}, {LabelStyle -> (FontFamily -> "Helvetica Neue")}]]

enter image description here

Jagra
  • 14,343
  • 1
  • 39
  • 81
  • I was about to ask, does it work within LineLegend? I assume from you update it does. – Mr.Wizard Dec 07 '12 at 18:19
  • @Mr.Wizard -- Yep, works with LineLegend too. Still can't think of a way to do it more directly. – Jagra Dec 07 '12 at 18:37
  • 2
    How about PlotLegends -> (Style[#, FontFamily -> "Helvetica Neue"] & /@ {"Sin", "Cos"})? – Mr.Wizard Dec 07 '12 at 18:44
  • The syntax description for PlotLegends suggests to me that there are no sub-options. The canonical way to style the legends would be to use one of the four xxLegend legends: The following legend constructors can be used to form commonly occurring legends: SwatchLegend, LineLegend, PointLegend, and BarLegend. – Sjoerd C. de Vries Dec 07 '12 at 18:54
  • @Mr.Wizard -- That works nicely, but one would think that we would have a more direct and simpler way to do it. – Jagra Dec 07 '12 at 18:55
  • @SjoerdC.deVries -- Yes, that seems like the most versatile way to do it. Sometimes, with questions like this, I feel like I can't quite think in the paradigm that the developer did. We, as a community, can usually come to it, I just wish they made the idea behind how they do specific things clearer in the documentation. This could just apply me. – Jagra Dec 07 '12 at 19:01
  • 1
    This is a duplicate of http://mathematica.stackexchange.com/q/15649/5 – rm -rf Dec 08 '12 at 00:55
  • @rm-rf -- I missed that one. I'd like to have my answer over there. I know how you usually feel about merges, but sine mine is the only one would you feel differently? ( Yes, I like testing the water; again. :o) ) – Mr.Wizard Dec 08 '12 at 10:57
  • @Mr.Wizard Although that question answers this one, your answer doesn't answer that one, since the OP there wants a global solution, not a local one (see comment under top answer: "But I am interested in changing the default font, not the font of the individual legend instance."). I guess you could merge, to provide an alternate in case someone was satisfied with a local solution, but note that you'll lose the accept :) – rm -rf Dec 08 '12 at 16:18

1 Answers1

3

Since no other answers are forthcoming, I have used a syntax like this in other places:

Plot[{Sin[x], Cos[x]}, {x, 0, 10}, 
 PlotLegends -> (Style[#, FontFamily -> "Helvetica Neue"] & /@ {"Sin", "Cos"})
]
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371