Control Legend Content

Properties for Controlling Legend Content

Graphics objects have two properties that control these options:

  • Annotation — Controls whether the graphics object appears in the legend and determines if the object or its children appear in the legend.

  • DisplayName — Specifies the text label used by the legend for the object. However, specifying a string with the legend command resets the value of DisplayName property.

Accessing the Annotation Control Objects

Querying the Annotation property returns the handle of an hg.Annotation object. The hg.Annotation object has a property called LegendInformation, which contains an hg.LegendEntry object. The hg.LegendEntry object has a property called IconDisplayStyle that you can set to one of three values.

IconDisplayStyle ValueBehavior
onRepresent this object in a figure legend.
offDo not include this object in a figure legend .
childrenDisplay legend entries for this object's children and not the object itself (applies only to objects that have children, otherwise, the same as on).

For example, if object_handle is the handle of a graphics object, use the following statements to set the object's IconDisplayStyle. In this case, the graphics object, object_handle, is not included in the legend because its IconDisplayStyle property is off.

hAnnotation = get(object_handle,'Annotation');
hLegendEntry = get(hAnnotation','LegendInformation');

Updating a Legend

If a legend exists and you change its IconDisplayStyle setting, you must call legend to update the display. See the legend command for the options available.

Was this topic helpful?