| Contents | Index |
The annotations of a MuPAD® plot may include a legend. A legend is a small table that relates the color of an object with some text explaining the object:
f := 3*x*sin(2*x):
g := 4*x^2*cos(x):
h := sin(4*x)/x:
plotfunc2d(f, g, h, x = 0..PI/2):

By default, legends are provided only by plotfunc2d and plotfunc3d. These routines define the legend texts as the expressions with which the functions are passed to plotfunc2d or plotfunc3d, respectively. A corresponding plot command using primitives of the plot library does not generate the legend automatically:
plot(plot::Function2d(f, x = 0..PI/2, Color = RGB::Red),
plot::Function2d(g, x = 0..PI/2, Color = RGB::Green),
plot::Function2d(h, x = 0..PI/2, Color = RGB::Blue)):

However, legends can be requested explicitly:
plot(plot::Function2d(f, x = 0..PI/2, Color = RGB::Red,
Legend = "Function 1: ".expr2text(f)),
plot::Function2d(g, x = 0..PI/2, Color = RGB::Green,
Legend = "Function 2: ".expr2text(g)),
plot::Function2d(h, x = 0..PI/2, Color = RGB::Blue,
Legend = "Function 3: ".expr2text(h))
):

Each graphical primitive accepts the attribute Legend. Passing this attribute to an object triggers several actions:
The object attribute LegendText is set to the given string.
The object attribute LegendEntryis set to TRUE.
A hint is sent to the scene containing the object advising it to use the scene attribute LegendVisible = TRUE.
The attributes LegendText and LegendEntry are visible in the “object inspector” of the interactive viewer (see section Viewer, Browser, and Inspector: Interactive Manipulation) and can be manipulated interactively for each single primitive after selection in the “object browser.” The attribute LegendVisible is associated with the scene object accessible via the “object browser.”
At most 20 entries can be displayed in a legend. If more entries are specified in a plot command, the surplus entries are ignored. Further, the legend may not cover more than 50%of the height of the drawing area of a scene. Only those legend entries fitting into this space are displayed; remaining entries are ignored.
If the attribute LegendText = TRUE is set for a primitive, its legend entry is determined as follows:
If the attribute LegendText is specified, its value is used for the legend text.
If no LegendText is specified, but the Name attribute is set, the name is used for the legend text.
If no Name attribute is specified either, the type of the object such as Function2d, Curve2d etc. is used for the legend text.
Here are all attributes relevant for legends:
Attributes for the legend
|
attribute name |
possible values/example |
meaning |
default |
browser entry |
|
string |
sets LegendText to the given string, LegendEntry to TRUE, and LegendVisible to TRUE. |
|
|
|
|
TRUE, FALSE |
add this object to the legend? |
TRUE for function graphs, curves, and surfaces, FALSE otherwise |
primitive |
|
|
string |
legend text |
|
primitive |
|
|
TRUE, FALSE |
legend on/off |
TRUE for plotfunc2d/3d, FALSE otherwise |
Scene2d/3d |
|
|
Top, Bottom |
vertical placement |
Bottom |
Scene2d/3d |
|
|
Left, Center, Right |
horizontal alignment |
Center |
Scene2d/3d |
|
|
see section Fonts |
font for the legend text |
sans-serif 8 |
Scene2d/3d |

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 |