Mathematica 9 is now available
Previous section-----Next section

2.10.15 Formats for Text in Graphics

$TextStyle = value set the default text style for all graphics
$FormatType = value set the default text format type for all graphics
TextStyle -> value an option for the text style in a particular graphic
FormatType -> value an option for the text format type in a particular graphic

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]=

"style" a cell style in your current notebook
FontSize -> n the size of font to use in printer's points
FontSlant -> "Italic" use an italic font
FontWeight -> "Bold" use a bold font
FontFamily -> "name" specify the name of the font family to use (e.g. "Times", "Courier", "Helvetica")

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.

StyleForm[expr, "style"] output expr in the specified cell style
StyleForm[expr, options] output expr using the specified font and style options
TraditionalForm[expr] output expr in TraditionalForm

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.



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.