2.10.16 Graphics Primitives for TextWith the Text graphics primitive, you can insert text at any position in two- or three-dimensional Mathematica graphics. Unless you explicitly specify a style or font using StyleForm, the text will be given in your current default style.
| Text[expr, {x, y}] | text centered at the point {x, y} | | Text[expr, {x, y}, {-1, 0}] | text with its left-hand end at {x, y} | | Text[expr, {x, y}, {1, 0}] | right-hand end at {x, y} | | Text[expr, {x, y}, {0, -1}] | centered above {x, y} | | Text[expr, {x, y}, {0, 1}] | centered below {x, y} | | Text[expr, {x, y}, {dx, dy}] | text positioned so that {x, y} is at relative coordinates {dx, dy} within the box that bounds the text |
Text[expr, {x, y}, {dx, dy}, {0, 1}]
| | text oriented vertically to read from bottom to top |
Text[expr, {x, y}, {dx, dy}, {0, -1}]
| | text that reads from top to bottom |
Text[expr, {x, y}, {dx, dy}, {-1, 0}]
| | text that is upside-down |
Two-dimensional text. | This generates five pieces of text, and displays them in a plot. | |
In[1]:=
Show[Graphics[ Table[ Text[Expand[(1 + x)^n], {n, n}], {n, 5} ] ], PlotRange -> All]
|
Out[1]=
|
|
| Here is some vertically oriented text with its left-hand side at the point {2, 2}. | |
In[2]:=
Show[Graphics[Text[ StyleForm["Some text", FontSize->14, FontWeight->"Bold"], {2, 2}, {-1, 0}, {0, 1}]], Frame -> True]
|
Out[2]=
|
|
When you specify an offset for text, the relative coordinates that are used are taken to run from to 1 in each direction across the box that bounds the text. The point {0, 0} in this coordinate system is defined to be center of the text. Note that the offsets you specify need not lie in the range to 1. Note that you can specify the color of a piece of text by preceding the Text graphics primitive with an appropriate RGBColor or other graphics directive.
| Text[expr, {x, y, z}] | text centered at the point {x, y, z} | | Text[expr, {x, y, z}, {sdx, sdy}] | text with a two-dimensional offset |
Three-dimensional text. | This loads a package containing definitions of polyhedra. | |
In[3]:=
<<Graphics`Polyhedra`
|
|
| This puts text at the specified position in three dimensions. | |
In[4]:=
Show[Graphics3D[{Dodecahedron[ ], Text["a point", {2, 2, 2}, {1, 1}]}]]
|
Out[4]=
|
|
Note that when you use text in three-dimensional graphics, Mathematica assumes that the text is never hidden by any polygons or other objects.
| option name | default value | | | Background | None | background color | | TextStyle | {} | style or font specification | | FormatType | StandardForm | format type |
Options for Text. | By default the text is just put straight on top of whatever graphics have already been drawn. | |
In[5]:=
Show[Graphics[{{GrayLevel[0.5], Rectangle[{0, 0}, {1, 1}]}, Text["Some text", {0.5, 0.5}]}]]
|
Out[5]=
|
|
| Now there is a rectangle with the background color of the whole plot enclosing the text. | |
In[6]:=
Show[Graphics[{{GrayLevel[0.5], Rectangle[{0, 0}, {1, 1}]}, Text["Some text", {0.5, 0.5}, Background->Automatic]}]]
|
Out[6]=
|
|
|