Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I change the base font style for all graphics objects, including the ones generated using plotting functions?

I would like to change this a single time and have it affect all graphics generated from there on (i.e. not specify the font on a plot by plot basis).

Say, I'd like to use 16 point Helvetica for everything by default.


My original thought was SetOptions[Graphics, BaseStyle -> {...}], but this will be overridden on graphics created using the various plotting functions (e.g. Plot).

My second try was changing the BaseStyle in the GraphicsBoxOptions of the notebook, but this didn't have an effect.

share|improve this question
    
Related: this and this –  Simon Woods Nov 11 '13 at 8:58
add comment

2 Answers

up vote 8 down vote accepted

To begin with your observation

SetOptions[Graphics, BaseStyle->{FontFamily -> "Helvetica"}]

doesn't work with Plot -- which seems unintuitive.

enter image description here

The styling for graphics is controlled by the Graphics style in the core.nb stylesheet.

enter image description here

We see here that font type and size etc. is explicitly specified so this seems to be taking precedence. For example having a local Graphics style in a private stylesheet with

Cell[StyleData["Graphics"],
 GraphicsBoxOptions->{BaseStyle->Directive[FontFamily->"Helvetica",RGBColor[1,0,0],FontSize->16]}]

has no effect. This is analogous to evaluating SetOptions as above.

So if you want to change the base font for all graphics what you need to do is override those specified font styles in the core.nb stylesheet. For example add this to your private stylesheet or to the stylesheet you regularly use.

Cell[StyleData["Graphics"],
 FontFamily->"Helvetica",
 FontSize->16,
 FontWeight->"Plain",
 FontColor->RGBColor[1,0,0]]

enter image description here

and you will see it has immediate effect (the pic below is the same cells as the screen grab above. No addition evaluation has taken place. After adding the new Graphics style the fonts automatically change):

enter image description here

share|improve this answer
add comment

While Mike's answer is of course very nice and useful I'd like to add a very simple Kernel-only idea: Just put all the relevant SetOptions statements into your init.m startup file. This is easily done, once, e.g., like:

Export[
 FindFile[
  "init.m"], (StringJoin[
   "Map[SetOptions[#, BaseStyle \[Rule] {FontFamily->\"Helvetica\", \
FontColor->Red, FontSize->16}]&,\n{",
   ExportString[
    Riffle[#, ","] &@
     ToExpression@
      Quiet@Select[
        Select[Names[
          "System`*"], ! StringMatchQ[#, "*Box*" | "$*"] &], ! 
          FreeQ[Options[Symbol[#]][[All, 1]], BaseStyle] &], "List"], 
   "}];\n"]
  ), "Text", CharacterEncoding -> "ASCII"]

This produces (check by FilePrint@FindFile["init.m"] ) :

Map[SetOptions[#, BaseStyle -> {FontFamily->"Helvetica", FontColor->Red, FontSize->16}]&,
{ActionMenu
,
AdjacencyGraph
,
AngularGauge
,
Animate
,
Animator
,
ArrayPlot
,
BarChart
,
BarChart3D
,
BodePlot
,
BooleanGraph
,
BubbleChart
,
BubbleChart3D
,
BulletGauge
,
ButterflyGraph
,
Button
,
ButtonBar
,
CancelButton
,
CandlestickChart
,
CayleyGraph
,
Checkbox
,
CheckboxBar
,
CirculantGraph
,
ClockGauge
,
ColorSetter
,
ColorSlider
,
Column
,
CommunityGraphPlot
,
CompleteGraph
,
CompleteKaryTree
,
ContourPlot
,
ContourPlot3D
,
ControllerManipulate
,
CycleGraph
,
DateListLogPlot
,
DateListPlot
,
DeBruijnGraph
,
DefaultButton
,
DensityHistogram
,
DensityPlot
,
DirectedGraph
,
DiscretePlot
,
DiscretePlot3D
,
DistributionChart
,
Dynamic
,
DynamicModule
,
DynamicNamespace
,
DynamicWrapper
,
FileNameSetter
,
FlipView
,
Framed
,
Graph
,
GraphComplement
,
GraphDifference
,
GraphDisjointUnion
,
Graphics
,
Graphics3D
,
GraphicsArray
,
GraphicsColumn
,
GraphicsGrid
,
GraphicsRow
,
GraphIntersection
,
GraphPlot
,
GraphPlot3D
,
GraphPower
,
GraphUnion
,
Grid
,
GridGraph
,
HararyGraph
,
HighlightGraph
,
Histogram
,
Histogram3D
,
HorizontalGauge
,
HypercubeGraph
,
Hyperlink
,
ImageHistogram
,
IncidenceGraph
,
InputField
,
Inset
,
InteractiveTradingChart
,
Interpretation
,
Item
,
KagiChart
,
KaryTree
,
KirchhoffGraph
,
KnightTourGraph
,
Labeled
,
LabeledSlider
,
LayeredGraphPlot
,
LineBreakChart
,
LineGraph
,
LineIntegralConvolutionPlot
,
ListAnimate
,
ListContourPlot
,
ListContourPlot3D
,
ListCurvePathPlot
,
ListDensityPlot
,
ListLineIntegralConvolutionPlot
,
ListLinePlot
,
ListLogLinearPlot
,
ListLogLogPlot
,
ListLogPlot
,
ListPicker
,
ListPlot
,
ListPlot3D
,
ListPointPlot3D
,
ListPolarPlot
,
ListStreamDensityPlot
,
ListStreamPlot
,
ListSurfacePlot3D
,
ListVectorDensityPlot
,
ListVectorPlot
,
ListVectorPlot3D
,
Locator
,
LocatorPane
,
LogLinearPlot
,
LogLogPlot
,
LogPlot
,
Manipulate
,
MatrixPlot
,
MenuView
,
MorphologicalGraph
,
Mouseover
,
NeighborhoodGraph
,
NicholsPlot
,
NyquistPlot
,
Opener
,
OpenerView
,
Overlay
,
PairedBarChart
,
PairedHistogram
,
PairedSmoothHistogram
,
Pane
,
Panel
,
PaneSelector
,
ParametricPlot
,
ParametricPlot3D
,
PasteButton
,
PathGraph
,
Periodogram
,
PetersenGraph
,
PieChart
,
PieChart3D
,
Plot
,
Plot3D
,
PointFigureChart
,
PolarPlot
,
Polygon
,
PopupMenu
,
PopupView
,
ProbabilityPlot
,
ProbabilityScalePlot
,
ProgressIndicator
,
QuantilePlot
,
RadioButton
,
RadioButtonBar
,
RandomGraph
,
RectangleChart
,
RectangleChart3D
,
RegionPlot
,
RegionPlot3D
,
ReliefPlot
,
RenkoChart
,
ReverseGraph
,
RevolutionPlot3D
,
RootLocusPlot
,
Rotate
,
Row
,
SectorChart
,
SectorChart3D
,
Setter
,
SetterBar
,
SimpleGraph
,
SingularValuePlot
,
Slider
,
Slider2D
,
SlideView
,
SmoothDensityHistogram
,
SmoothHistogram
,
SmoothHistogram3D
,
Spectrogram
,
SphericalPlot3D
,
StarGraph
,
StreamDensityPlot
,
StreamPlot
,
Subgraph
,
TabView
,
Text
,
ThermometerGauge
,
Toggler
,
TogglerBar
,
Tooltip
,
TradingChart
,
TreeForm
,
TreeGraph
,
TreePlot
,
Trigger
,
TuranGraph
,
UndirectedGraph
,
VectorDensityPlot
,
VectorPlot
,
VectorPlot3D
,
VerticalGauge
,
VerticalSlider
,
WaveletImagePlot
,
WaveletListPlot
,
WaveletMatrixPlot
,
WaveletScalogram
,
WeightedAdjacencyGraph
,
WheelGraph}];
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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