Skip to Main Content Skip to Search
Product Documentation

Legends

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):

MuPAD graphics

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)):

MuPAD graphics

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))
):

MuPAD graphics

Each graphical primitive accepts the attribute Legend. Passing this attribute to an object triggers several actions:

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:

Here are all attributes relevant for legends:

Attributes for the legend

attribute name 

possible values/example 

meaning 

default 

browser entry 

Legend

string 

sets LegendText to the given string, LegendEntry to TRUE, and LegendVisible to TRUE

 

 

LegendEntry

TRUE, FALSE

add this object to the legend? 

TRUE for function graphs, curves, and surfaces, FALSE otherwise 

primitive

LegendText

string 

legend text 

 

primitive

LegendVisible

TRUE, FALSE

legend on/off 

TRUE for plotfunc2d/3d, FALSE otherwise 

Scene2d/3d

LegendPlacement

Top, Bottom

vertical placement 

Bottom

Scene2d/3d

LegendAlignment

Left, Center, Right

horizontal alignment 

Center

Scene2d/3d

LegendFont

see section Fonts

font for the legend text 

sans-serif 8 

Scene2d/3d

 

  


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