Legends provide a key to the various data plotted on a graph. The following picture shows the legend for a graph of several functions of a variable plotted with lines of different colors. A graph can have only one legend, which applies to and will symbolize all data series contained by an axes, according to their form (e.g., lines, bars, pies, etc.). You can assign an appropriate string to each line in the legend.
Add a legend by clicking the legend button in the toolbar or by selecting Legend from the Insert menu. When plot editing is enabled, you can select and then move and resize the legend.
To display a legend with more than 50 entries, you must use the legend function, as the legend toolbar button is limited to displaying legends for 50 elements.
By default, the legend labels each plotted object (line, surface, etc.) with the strings data1, data2, etc. You can change this text by double-clicking on the text to enable edit mode. In edit mode, you can retype the text string.
You can use TeX characters in the text strings to produce symbols. You can disable interpretation of characters as TeX sequences by selecting none from the Interpreter submenu of the legend's right-click context menu.
See the Table of TeX symbols in the Text Properties reference documentation for more information.
There are a number of ways to position the legend.
Enable plot edit mode, select the legend, and drag it to the desired location.
Right-click the legend to display its context menu, mouse over Location, and select one of the predefined locations from the submenu.
Right-click the legend to display its context menu and select Properties to display the Property Editor, which provides a graphical device for positioning the legend.
You can also select a vertical or horizontal orientation for the legend. Use the Orientation item in the context menu to make this selection.
Specify the following legend characteristics from the context menu:
Color — Set the background color of the legend. In addition, you can specify the Color property as 'none' to make the legend background be transparent.
EdgeColor — Set the color of the line enclosing the legend box.
You can use a colorspec or an RGB color triplet to set the above two properties.
LineWidth — Set the width of the edge line.
Font — Set the font, font style, and font size of the text used in the legend.
Interpreter — Set the text Interpreter property to use TeX or plain text.
Orientation — Orient the legend entries side by side (horizontal) or on top of each other.
Properties — Display the Property Editor with legend properties.
Show M-code — Generates MATLAB® code for recreating the legend.