ContentsIndexReferenceHome
PreviousUpNext
clickableLegend
MATLAB
[LEGH,OBJH,OUTH,OUTM] = clickableLegend([AX],{[string1],...
              [stringN]},'group',grps,'displayedLines',lines, ...)
Description

clickableLegend is a wrapper around the Matlab function LEGEND that provides the added functionality to turn on and off (hide or show) a graphics object (line or patch) by clicking on its text label in the legend. Call with no inputs to place a clickableLegend on the current plot. Its usage is the same as the Matlab function. For further information please see the LEGEND documentation.

Parameters
Parameters 
Description 
AX [scalar] 
(Optional) Axes handle for legend 
string1..stringN [string] 
(Optional) Strings for legend labels. Also string1 could be a cell array containing all labels. 
grps [vector] 
(Optional) Must be preceded by keyword 'groups'. A vector specifying the group membership for every line object. The grouping parameter lets you have a group of lines represented and controlled by one entry in the legend. 
lines [vector] 
(Optional) Must be preceded by the keyword 'displayedLines'. A vector of indices corresponding to the lines or groups that should be displayed initially. 
Return Values
Return Values 
Description 
LEGH [scalar] 
A handle to the legend axes 
OBJH [vector] 
A vector containing handles for the text, lines, and patches in the legend 
OUTH [vector] 
A vector of handles to the lines and patches in the plot 
OUTM [cell] 
A cell array containing the text in the legend 
Notes

  1. If you save the figure and re-load it, the toggling functionality is not automatically re-enabled. To restore it, simply call clickableLegend with no arguments.
 

  1. To prevent the axis from automatically scaling every time a line is turned on and off, issue the command: axis manual

Examples

  • z = peaks(100);
  • plot(z(:,26:5:50)); grid on; axis manual;
  • clickableLegend({'Line1','Line2','Line3','Line4','Line5'},'Location', 'NorthWest');
  • f = plot([1:10;1:2:20]','x'); hold on;
  • g = plot(sin([1:10;1:2:20]'),'r-');
  • h = plot(11:20,rand(5,10)*5,'b:');
  • clickableLegend([f;g;h], {'Line1','Line2','Line3'},'groups', [1 1 2 2 3 3 3 3 3], 'displayedLines', [2 3]);

See Also

legend

Group
Made with Doc-O-Matic.
Copyright (c) MZA Associates 2009. All rights reserved.
What do you think about this topic? Send feedback!