Add legend to axes
legend('show')
creates a legend that includes
items for all charts in the current axes. For the labels, the legend
uses the text from the DisplayName
properties of
the charts. If the DisplayName
property is empty,
then the legend uses a label of the form 'dataN'
.
If there are no charts in the axes, then this command creates an empty
legend. If a legend exists, then this command ensures that it is visible.
legend(
sets
the legend labels. Specify the labels as a list of character vectors,
such as label1,...,labelN
)legend('Jan','Feb','Mar')
.
legend(
sets
the labels using a cell array of character vectors or a character
matrix; for example, labels
)legend({'Jan','Feb','Mar'})
.
legend(
sets
legend properties using one or more name-value pair arguments. You
must specify the labels using a cell array; for example, labels
,Name,Value
)legend({'A','B'},'FontSize',12)
.
legend(
only
includes items in the legend for the graphics objects listed in obj
,___)obj
.
Specify the graphics objects before specifying the labels.
legend(___,'Location',
sets
the legend location. For example, lcn
)'Location','northeast'
creates
the legend in the upper right corner of the axes. You can use this
option after any of the input argument combinations in the previous
syntax group.
legend(___,'Orientation',
,
where ornt
)ornt
is 'horizontal'
,
displays the legend items side-by-side. The default for ornt
is 'vertical'
,
which stacks the items vertically.
returns
the legend object. Use lgd
= legend(___)lgd
to query and set properties
of the legend after it is created. For a list of properties, see Legend Properties.
[
additionally returns the objects
used to create the legend icons, the objects plotted in the graph,
and an array of the label text.lgd
,icons
,plots
,txt
]
= legend(___)
Note:
This syntax is not recommended. It creates a legend that does
not support all graphics features. Instead, use the |
legend(
controls
the visibility of the legend, where visibilityOption
)visibilityOption
is 'hide'
or 'toggle'
.
legend('off')
deletes the legend.