This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Short explanatory text for legend

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Value Summary

OptionalText string


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


LegendText is a technical internal attribute. You will most likely want to use the library interface attribute Legend in order to set legend entries.

To have a legend entry, the object must have Legend set to TRUE and LegendVisible must be TRUE for the enclosing scene. Cf. Example 1.

If LegendText is unset, but Legend and LegendVisible are TRUE, the legend entry is taken from the attribute Name. If that is unset, too, the name of the object type is displayed. Cf. Example 2.


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)

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)

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"),

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)

See Also

MuPAD Functions


Was this topic helpful?