TransWikia.com

How do I change the LabelStyle for all graphics producing functions programmatically (only for the current session)

Mathematica Asked on February 9, 2021

I want to change the default label style (or every Font appearing in graphics if easier) programmatically for the current session. Specifically I want to change the color to black (from the default grey).

For a single plot this can be done by specifying LabelStyle -> Black. One might hope that the same method that works for some other settings such as ImageSize also works for other options (see https://mathematica.stackexchange.com/a/228506/45020). However, the following does nothing:

SetOptions[EvaluationNotebook[], 
 GraphicsBoxOptions -> {"LabelStyle" -> Black}]

The reason is probably the one explained in https://mathematica.stackexchange.com/a/36770/45020. I tried implementing the solution from there but I fail at changing the stylesheet appropriately (let alone doing it programmatically).

The other solution to that question is programmatical but for some reason it fails to change the FontColor. (It does work in all other ways.)

3 Answers

This might have unforeseen downsides but one way is to add a definition for Graphics itself. Something like:

Unprotect[Graphics];
Graphics[any__]/;FreeQ[{any},LabelStyle]:=Graphics[any,LabelStyle->Black];

Answered by Kvothe on February 9, 2021

You can use $PrePrint as follows:

$PrePrint = If[MemberQ[{Graphics, Graphics3D}, Head@#], 
    Show[#, LabelStyle -> {24, FontFamily -> "Comic Sans MS", Red}], #] &;

Plot[Sin[x], {x, 0, 2 Pi}]

enter image description here

Plot3D[Sin[x y], {x, 0, 2 Pi}, {y, 0, 2 Pi}, PlotLabel -> "LABEL"]

enter image description here

Answered by kglr on February 9, 2021

You can modify the current notebook's style sheet:

SetOptions[EvaluationNotebook[], 
 StyleDefinitions -> Cell[StyleData["GraphicsLabel"], Black]]

Answered by Simon Woods on February 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP