Documentation Center

  • Trial Software
  • Product Updates

plot::Text2d

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

plot::Text2d(text, [x, y], <a = amin .. amax>, options)

Description

plot::Text2d draws a text at a given position (x, y) (the "anchor point"). The attributes VerticalAlignment and HorizontalAlignment determine the alignment of the text w.r.t. its anchor.

Size, text color, font type etc. are controlled by the attribute TextFont.

A text may consist of several lines. The newline character in MuPAD® strings ist \n. For example: "first line\nsecond line".

The attribute TextRotation allows to rotate the text on the screen.

The text of a text object can be animated if it is passed as a procedure that returns the text string during runtime. Cf. Example 5.

Attributes

AttributePurposeDefault Value
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
Framesthe number of frames in an animation50
HorizontalAlignmenthorizontal alignment of text objects w.r.t. their coordinatesLeft
Legendmakes a legend entry 
LegendTextshort explanatory text for legend 
LegendEntryadd this object to the legend?FALSE
Namethe name of a plot object (for browser and legend) 
ParameterEndend value of the animation parameter 
ParameterNamename of the animation parameter 
ParameterBegininitial value of the animation parameter 
ParameterRangerange of the animation parameter 
Positionpositions of cameras, lights, and text objects 
PositionXx-positions of cameras, lights, and text objects 
PositionYy-positions of cameras, lights, and text objects 
Textthe text of a text object 
TextFontfont of text objects[" sans-serif ", 11]
TextRotationrotation of a 2D text0
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
Titleobject title 
TitleFontfont of object titles[" sans-serif ", 11]
TitlePositionposition of object titles 
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component 
TitlePositionYposition of object titles, y component 
VerticalAlignmentvertical alignment of text objects w.r.t. their coordinatesBaseLine
VisiblevisibilityTRUE
VisibleAfterobject visible after this time value 
VisibleBeforeobject visible until this time value 
VisibleFromToobject visible during this time range 
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE

Examples

Example 1

We draw the text string `Hello world!' at the anchor point (1, 2) which is indicated by a red dot:

plot(plot::Rectangle(0..2, 0..4),
     plot::Point2d([1, 2]),
     plot::Text2d("Hello world!", [1, 2],
                  HorizontalAlignment = Center), 
     Axes = Frame, TextFont = [24],
     PointColor = RGB::Red, PointSize = 3*unit::mm)

Example 2

We animate the anchor points of the following texts and demonstrate various alignment possibilities:

plot(plot::Circle2d(1),
     plot::Point2d([sin(a), cos(a)], a = 0..2*PI), 
     plot::Point2d([cos(a), -sin(a)], a = 0..2*PI),
     plot::Point2d([-sin(a), -cos(a)], a = 0..2*PI),
     plot::Point2d([-cos(a), sin(a)], a = 0..2*PI),
     PointColor = RGB::Red, PointSize = 3*unit::mm,
     plot::Text2d("Hello (1)", [sin(a), cos(a)], a = 0..2*PI),
     plot::Text2d("Hello (2)", [cos(a), -sin(a)], a = 0..2*PI,
                  HorizontalAlignment = Left,
                  VerticalAlignment = BaseLine),
     plot::Text2d("Hello (3)", [-sin(a), -cos(a)], a = 0..2*PI,
                  HorizontalAlignment = Center,
                  VerticalAlignment = Top),
     plot::Text2d("Hello (4)", [-cos(a), sin(a)], a = 0..2*PI,
                  HorizontalAlignment = Right,
                  VerticalAlignment = Bottom),
     TextFont = [Italic, 24], Axes = Frame)

Example 3

A text may consist of several lines. The newline character in MuPAD strings is \n:

plot(plot::Text2d("A text can\nhave several\nlines", 
                  [sin(a), cos(a)], a = 0..2*PI),
     Axes = Frame, TextFont = [20])

Example 4

The attribute TextRotation allows to rotate a 2D text on the screen:

plot(plot::Circle2d(sqrt(2)),
     plot::Text2d("Hello (1)", [ 1, 1], 
                  HorizontalAlignment = Left,
                  TextRotation = PI/4),
     plot::Text2d("Hello (2)", [ 1,-1], 
                  HorizontalAlignment = Left,
                  TextRotation = -PI/4),
     plot::Text2d("Hello (3)", [-1,-1], 
                  HorizontalAlignment = Right,
                  TextRotation = PI/4),
     plot::Text2d("Hello (4)", [-1, 1], 
                  HorizontalAlignment = Right,
                  TextRotation = -PI/4),
     HorizontalAlignment = Left, TextFont = [20])

Example 5

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)

Parameters

text

The text: a string. Alternatively, a procedure that accepts one input parameter a (the animation parameter) and returns a string.

text is equivalent to the attribute Text.

x, y

The position of the text. The coordinates x and y must be real numerical values or arithmetical expressions of the animation parameter a.

x, y are equivalent to the attributes Position, PositionX, PositionY.

a

Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.

See Also

MuPAD Functions

MuPAD Graphical Primitives

Was this topic helpful?