This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / The Mathematica Book / Principles of Mathematica / The Structure of Graphics and Sound /

2.10.15 Formats for Text in Graphics

Specifying formats for text in graphics.

Here is a plot with default settings for all formats.

In[1]:= Plot[Sin[x]^2, {x, 0, 2 Pi}, PlotLabel->Sin[x]^2]

Out[1]=

Here is the same plot, but now using a 7-point italic font.

In[2]:= Plot[Sin[x]^2, {x, 0, 2 Pi}, PlotLabel->Sin[x]^2,
TextStyle->{FontSlant->"Italic", FontSize->7}]

Out[2]=

This uses TraditionalForm rather than StandardForm.

In[3]:= Plot[Sin[x]^2, {x, 0, 2 Pi}, PlotLabel->Sin[x]^2,
FormatType -> TraditionalForm]

Out[3]=

This tells Mathematica what default text style to use for all subsequent plots.

In[4]:= $TextStyle = {FontFamily -> "Times", FontSize -> 7}

Out[4]=

Now all the text is in 7-point Times font.

In[5]:= Plot[Sin[x]^2, {x, 0, 2 Pi}, PlotLabel->Sin[x]^2]

Out[5]=

Typical elements used in the setting for TextStyle or $TextStyle.

If you use the standard notebook front end for Mathematica, then you can set $TextStyle or TextStyle to be the name of a cell style in your current notebook. This tells Mathematica to use that cell style as the default for formatting any text that appears in graphics.

You can also explicitly specify how text should be formatted by using options such as FontSize and FontFamily. Note that FontSize gives the absolute size of the font to use, measured in units of printer's points, with one point being inches. If you resize a plot, the text in it will not by default change size: to get text of a different size you must explicitly specify a new value for the FontSize option.

Changing the formats of individual pieces of output.

This outputs the plot label using the section heading style in your current notebook.

In[6]:= Plot[Sin[x]^2, {x, 0, 2 Pi},
PlotLabel->StyleForm[Sin[x]^2, "Section"]]

Out[6]=

This uses the section heading style, but modified to be in italics.

In[7]:= Plot[Sin[x]^2, {x, 0, 2 Pi},
PlotLabel->StyleForm[Sin[x]^2, "Section",
FontSlant->"Italic"]]

Out[7]=

This produces TraditionalForm output, with a 12-point font.

In[8]:= Plot[Sin[x]^2, {x, 0, 2 Pi},
PlotLabel->StyleForm[TraditionalForm[Sin[x]^2],
FontSize->12]]

Out[8]=

You should realize that the ability to refer to cell styles such as "Section" depends on using the standard Mathematica notebook front end. Even if you are just using a text-based interface to Mathematica, however, you can still specify formatting of text in graphics using options such as FontSize. The complete collection of options that you can use is given in Section 2.11.10.