3
$\begingroup$

Gustavo Delfino's answer to an earlier question showed that it is possible to use the third argument to Placed to format text in a BarChart legend as desired. For example, without this argument, the legend text in the example below would still be small and in Times, even though I have used SetOptions to style BaseStyle for BarChart, Graphics, etc.

BarChart[RandomVariate[NormalDistribution[0, 0.6], 40], 
 ChartStyle -> Join[ConstantArray[Green, {39}], {Orange}], 
 ChartLegends -> Placed[Join[ConstantArray[None, {39}], {"Preliminary estimates"}], 
   Bottom, Style[#, FontFamily -> "Arial", FontSize -> 14] &]]

enter image description here

Is there a way to set this globally? I’d like to enforce the font style of legends in a package, the way I have already done for the frame around the legend using Mr.Wizard’s answer to an earlier question of mine on StackOverflow. I would have thought some setting of BaseStyle should work but these are the only (undocumented) options that Legending`GridLegend takes:

Options[Legending`GridLegend]

{"LegendPlacementFunction" -> Automatic, 
 LegendAppearance -> Automatic, 
 Legending`LegendContainer -> Automatic, 
 Legending`LegendHeading -> None, Legending`LegendImage -> Automatic, 
 Legending`LegendImage -> Automatic, 
 Legending`LegendLayout -> Automatic, 
 Legending`LegendPosition -> Automatic, 
 Legending`LegendSize -> Automatic}
$\endgroup$
4
  • $\begingroup$ If it's a package, then why not supply a custom barchart function that applies the styling in the definition, thereby hiding it from the end-user? $\endgroup$
    – rm -rf
    Jun 3, 2012 at 16:34
  • $\begingroup$ @R.M actually it is already a custom barchart function, but I'm trying to work out how to introduce simple legending into that function. Or I could just leave it to the successful tender for the contract to write the GUI. $\endgroup$
    – Verbeia
    Jun 3, 2012 at 23:48
  • $\begingroup$ makes more sense to leave it to the latter. They probably have that sorted. $\endgroup$ Jun 4, 2012 at 0:22
  • $\begingroup$ @MikeHoneychurch :) $\endgroup$
    – Verbeia
    Jun 4, 2012 at 1:34

1 Answer 1

3
$\begingroup$

I'm not certain I understand your requirements, but if you liked my prior answer that you referenced, why not use it here too? Since the LegendContainer is applied to the legend you can use it to insert directives:

SetOptions[Legending`GridLegend, 
  Legending`LegendContainer -> (Append[#, {Red, Bold, FontFamily -> "Helvetica"}] &) ]

BarChart[{{1, 2, 3}, {1, 3, 2}, {5, 2}}, 
  ChartLegends -> {"some", "text", "here"} ]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Thanks! I hadn't realised that this could be done as well as including the Identity trick in your last answer. (There's a blog post in here somewhere...) $\endgroup$
    – Verbeia
    Jun 4, 2012 at 12:05
  • $\begingroup$ @Verbeia similar use: mathematica.stackexchange.com/a/4586/121 $\endgroup$
    – Mr.Wizard
    Jun 9, 2012 at 8:57

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.