2
$\begingroup$

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.)

$\endgroup$
0

3 Answers 3

3
$\begingroup$

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

$\endgroup$
1
$\begingroup$

You can modify the current notebook's style sheet:

SetOptions[EvaluationNotebook[], 
 StyleDefinitions -> Cell[StyleData["GraphicsLabel"], Black]]
$\endgroup$
0
$\begingroup$

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];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.