Documentation Center

  • Trial Software
  • Product Updates

Text

Text of a text object

Value Summary

MandatoryString or function

Graphics Primitives

ObjectsText Default Values
plot::Text2d, plot::Text3d 

Description

The attribute Text represents the text of a text object. It may be a text string or a function generating a text string at runtime.

The Text attribute represents the text in text objects of type plot::Text2d and plot::Text3d. When creating a text object such as

t := plot::Text2d("hello world", [0, 0]),

the text is the first argument. Internally, it is stored as the attribute Text = "hello world" and can be accessed and changed via a slot call t::Text.

In most cases, the text is given as a string.

    Note:   Note that this string has to be quoted when changing it in the "property inspector" of the interactive graphics tool (see section Viewer, Browser, and Inspector: Interactive Manipulation of this document). If the string contains white space and the quotes are removed, the recalculation following the change will produce a syntax error!

A text given by a fixed string cannot be animated. Use a procedure to create animated texts.

The attribute Text can be a procedure that is called at runtime with the animation parameter as the only input parameter. The return value is used as the text of the text object in the corresponding frame of the animation. If the result is not a string, expr2text is applied to the return value.

Examples

Example 1

Usually, a text is given by a string:

t := plot::Text2d("hello world", [1, 1], TextFont = [24]):
plot(t)

We access and change the text:

t::Text

t::Text := "HELLO WORLD":
plot(t)

The same message in 3D:

plot(plot::Text3d("HELLO WORLD", [1, 1, 1],
                  TextFont = [24]))

delete t:

Example 2

The text of a text object can be animated if the text string is provided by a procedure. We use stringlib::formatf to format the animation parameter that is passed to the procedure as a floating-point number for each frame of the animation:

plot(plot::Rectangle(-1..1, -1..1),
     plot::Text2d(a -> stringlib::formatf(a, 2, 5)." sec",
                  [0, 0], a = 0..20,
                  TextFont = [60], 
                  HorizontalAlignment = Center, 
                  VerticalAlignment = Center),
     Axes = Frame, Frames = 201, TimeRange = 0..20)

Here is the corresponding example in 3D:

plot(plot::Text3d(a -> stringlib::formatf(a, 2, 5)." sec",
                  [0, 0, 0], a = 0..20,
                  TextFont = [60], 
                  HorizontalAlignment = Center, 
                  VerticalAlignment = Center),
     Axes = Frame, Frames = 201, TimeRange = 0..20)

See Also

MuPAD Functions

Was this topic helpful?