Skip to Main Content Skip to Search
Product Documentation

LegendTextshort explanatory text for legend

LegendText sets the text for the legend entry of an object.

→ Examples

Attribute

Type

Value

See Also:

Legend, LegendVisible, Name

See Also:

Section Legends in this document.

Details:

Example 1

We create a few objects with values for LegendText set:

f := plot::Function2d(sin(x), x = 0..PI,
                      LegendText = "f(x)", Color = RGB::Red):
g := plot::Function2d(cos(x), x = 0..PI,
                      LegendText = "f'(x)", Color = RGB::Blue):
p := plot::Point2d([2, sin(2)], PointSize = 3*unit::mm,
                   LegendText = "(2; f(2))", Color = RGB::Black):

Switching on the legend, we plot these objects:

plot(f, g, p, LegendVisible = TRUE)

MuPAD graphics

As we can see, only the function objects show up in the legend. If p is supposed to be shown there, too, we must explicitly set LegendEntry to TRUE:

p::LegendEntry := TRUE:
plot(f, g, p, LegendVisible = TRUE)

MuPAD graphics

Example 2

If an object has a legend entry, but LegendText is not set, the first fall-back is the Name attribute of the object:

plot(plot::Function3d(sin(x^2 + y^2), x = -2..2, y = -2..2,
                      Color = RGB::Green, FillColorType = Flat,
                      LegendText = "LegendText: sin",
                      Name = "Name: sin"),
     plot::Function3d(cos(x + y), x = -2..2, y = -2..2,
                      Color = RGB::Blue, FillColorType = Flat,
                      Name = "Name: cos"),
     LegendVisible)

MuPAD graphics

As a last resort, the name of the type of object is used:

plot(plot::Rectangle(0..1, 0..1),
     plot::Point2d(frandom(), frandom()),
     plot::Point2d(frandom(), frandom()),
     plot::Point2d(frandom(), frandom()),
     plot::Point2d(frandom(), frandom()),
     plot::Point2d(frandom(), frandom()),
     LegendEntry = TRUE, LegendVisible = TRUE)

MuPAD graphics

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS