This is a static copy of a profile report

Home

legend (2 calls, 0.933 sec)
Generated 18-Mar-2011 23:31:43 using cpu time.
M-function in file /Applications/MATLAB_R2010a.app/toolbox/matlab/scribe/legend.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
generateBEMmeshM-function2
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
287
[h,msg] = make_legend(ha,varar...
20.881 s94.4%
223
if isa(h,'scribe.colorbar') ||...
20.010 s1.1%
222
h = handle(ha);
20.010 s1.1%
188
end
20.010 s1.1%
155
elseif (narg==1 && isc...
20.010 s1.1%
All other lines  0.010 s1.1%
Totals  0.933 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
legend>make_legendM-subfunction20.881 s94.4%
gcfM-function20 s0%
Self time (built-ins, overhead, etc.)  0.052 s5.6%
Totals  0.933 s100% 
M-Lint results
Line numberMessage
296An M-Lint message was once suppressed here, but the message is no longer generated.
Coverage results
[ Show coverage for parent directory ]
Total lines in function323
Non-code lines (comments, blank lines)167
Code lines (lines that can run)156
Code lines that did run45
Code lines that did not run111
Coverage (did run/can run)28.85 %
Function listing
   time   calls  line
1 function [leg,labelhandles,outH,outM]=legend(varargin)
2 %LEGEND Display legend.
3 % LEGEND(string1,string2,string3, ...) puts a legend on the current plot
4 % using the specified strings as labels. LEGEND works on line graphs,
5 % bar graphs, pie graphs, ribbon plots, etc. You can label any
6 % solid-colored patch or surface object. The fontsize and fontname for
7 % the legend strings matches the axes fontsize and fontname.
8 %
9 % LEGEND(H,string1,string2,string3, ...) puts a legend on the plot
10 % containing the handles in the vector H using the specified strings as
11 % labels for the corresponding handles.
12 %
13 % LEGEND(M), where M is a string matrix or cell array of strings, and
14 % LEGEND(H,M) where H is a vector of handles to lines and patches also
15 % works.
16 %
17 % LEGEND(AX,...) puts a legend on the axes with handle AX.
18 %
19 % LEGEND OFF removes the legend from the current axes and deletes
20 % the legend handle.
21 % LEGEND(AX,'off') removes the legend from the axis AX.
22 %
23 % LEGEND TOGGLE toggles legend on or off. If no legend exists for the
24 % current axes one is created using default strings. The default
25 % string for an object is the value of the DisplayName property
26 % if it is non-empty and otherwise it is a string of the form
27 % 'data1','data2', etc.
28 % LEGEND(AX,'toggle') toggles legend for axes AX
29 %
30 % LEGEND HIDE makes legend invisible.
31 % LEGEND(AX,'hide') makes legend on axes AX invisible.
32 % LEGEND SHOW makes legend visible. If no legend exists for the
33 % current axes one is created using default strings.
34 % LEGEND(AX,'show') makes legend on axes AX visible.
35 %
36 % LEGEND BOXOFF makes legend background box invisible when legend is
37 % visible.
38 % LEGEND(AX,'boxoff') for axes AX makes legend background box invisible when
39 % legend is visible.
40 % LEGEND BOXON makes legend background box visible when legend is visible.
41 % LEGEND(AX,'boxon') for axes AX making legend background box visible when
42 % legend is visible.
43 %
44 % LEGH = LEGEND returns the handle to legend on the current axes or
45 % empty if none exists.
46 %
47 %
48 % LEGEND(...,'Location',LOC) adds a legend in the specified
49 % location, LOC, with respect to the axes. LOC may be either a
50 % 1x4 position vector or one of the following strings:
51 % 'North' inside plot box near top
52 % 'South' inside bottom
53 % 'East' inside right
54 % 'West' inside left
55 % 'NorthEast' inside top right (default for 2-D plots)
56 % 'NorthWest' inside top left
57 % 'SouthEast' inside bottom right
58 % 'SouthWest' inside bottom left
59 % 'NorthOutside' outside plot box near top
60 % 'SouthOutside' outside bottom
61 % 'EastOutside' outside right
62 % 'WestOutside' outside left
63 % 'NorthEastOutside' outside top right (default for 3-D plots)
64 % 'NorthWestOutside' outside top left
65 % 'SouthEastOutside' outside bottom right
66 % 'SouthWestOutside' outside bottom left
67 % 'Best' least conflict with data in plot
68 % 'BestOutside' least unused space outside plot
69 % If the legend does not fit in the 1x4 position vector the position
70 % vector is resized around the midpoint to fit the preferred legend size.
71 % Moving the legend manually by dragging with the mouse or setting
72 % the Position property will set the legend Location property to 'none'.
73 %
74 % LEGEND(...,'Orientation',ORIENTATION) creates a legend with the
75 % legend items arranged in the specified ORIENTATION. Allowed
76 % values for ORIENTATION are 'vertical' (the default) and 'horizontal'.
77 %
78 % [LEGH,OBJH,OUTH,OUTM] = LEGEND(...) returns a handle LEGH to the
79 % legend axes; a vector OBJH containing handles for the text, lines,
80 % and patches in the legend; a vector OUTH of handles to the
81 % lines and patches in the plot; and a cell array OUTM containing
82 % the text in the legend.
83 %
84 % Examples:
85 % x = 0:.2:12;
86 % plot(x,bessel(1,x),x,bessel(2,x),x,bessel(3,x));
87 % legend('First','Second','Third');
88 % legend('First','Second','Third','Location','NorthEastOutside')
89 %
90 % b = bar(rand(10,5),'stacked'); colormap(summer); hold on
91 % x = plot(1:10,5*rand(10,1),'marker','square','markersize',12,...
92 % 'markeredgecolor','y','markerfacecolor',[.6 0 .6],...
93 % 'linestyle','-','color','r','linewidth',2); hold off
94 % legend([b,x],'Carrots','Peas','Peppers','Green Beans',...
95 % 'Cucumbers','Eggplant')
96
97
98 % Unsupported APIs for internal use:
99 % LEGEND(...,Pos) places the legend in the specified
100 % location:
101 % 0 = Automatic "best" placement (least conflict with data)
102 % 1 = Upper right-hand corner (default)
103 % 2 = Upper left-hand corner
104 % 3 = Lower left-hand corner
105 % 4 = Lower right-hand corner
106 % -1 = To the right of the plot
107 %
108 % LOC strings can be abbreviated NE, SO, etc or lower case.
109 %
110 % LEGEND('-DynamicLegend') or LEGEND(AX,'-DynamicLegend')
111 % creates a legend that adds new entries when new plots appear
112 % in the peer axes.
113 %
114 % LEGEND(LI,string1,string2,string3) creates a legend for legendinfo
115 % objects LI with strings string1, etc.
116 % LEGEND(LI,M) creates a legend for legendinfo objects LI where M is a
117 % string matrix or cell array of strings corresponding to the legendinfo
118 % objects.
119
120 % Copyright 1984-2008 The MathWorks, Inc.
121
122 % First we check whether Handle Graphics uses MATLAB classes
2 123 isHGUsingMATLABClasses = feature('HGUsingMATLABClasses');
124
2 125 if isHGUsingMATLABClasses
126 if nargout == 0
127 legendHGUsingMATLABClasses(varargin{:});
128 elseif nargout == 1
129 leg = legendHGUsingMATLABClasses(varargin{:});
130 elseif nargout == 2
131 [leg,labelhandles] = legendHGUsingMATLABClasses(varargin{:});
132 elseif nargout == 3
133 [leg,labelhandles,outH] = legendHGUsingMATLABClasses(varargin{:});
134 else
135 [leg,labelhandles,outH,outM] = legendHGUsingMATLABClasses(varargin{:});
136 end
2 137 else
2 138 narg = nargin;
2 139 if (narg > 1 && ischar(varargin{1}) && ~ischar(varargin{2}) && strcmp(varargin{1},'v6'))
140 warning(['MATLAB:', mfilename, ':DeprecatedV6Argument'],...
141 ['The ''v6'' argument to %s is deprecated,',...
142 ' and will no longer be supported in a future release.'], upper(mfilename));
143 if nargout == 0
144 legendv6(varargin{2:end});
145 elseif nargout == 1
146 leg = legendv6(varargin{2:end});
147 elseif nargout == 2
148 [leg,labelhandles] = legendv6(varargin{2:end});
149 else
150 [leg,labelhandles,outH,outM] = legendv6(varargin{2:end});
151 end
152 return;
153
154 % look for special callbacks into legend for V6 legend code
0.01 2 155 elseif (narg==1 && ischar(varargin{1}) && ...
156 isvector(varargin{1}) && ...
157 size(varargin{1},2) == length(varargin{1}) && ...
158 any(strcmp(varargin{1},{'DeleteLegend','ResizeLegend'})))
159 legendv6(varargin{:});
160 return;
161
2 162 elseif (narg==2 && ischar(varargin{1}) && ...
163 isvector(varargin{1}) && ...
164 size(varargin{1},2) == length(varargin{1}) && ...
165 any(strcmp(varargin{1},...
166 {'EditLegend','ShowLegendPlot','RestoreSize','RecordSize'})))
167 legendv6(varargin{:});
168 return
169 end
170 % HANDLE FINDLEGEND CASES FIRST
2 171 if narg==2 && ...
172 ischar(varargin{1}) && ...
173 isequal(lower(varargin{1}),'-find') && ...
174 ~isempty(varargin{2}) && ...
175 ishandle(varargin{2}) && ...
176 strcmpi(get(varargin{2},'type'),'axes')
177 if nargout<=1
178 leg = find_legend(varargin{2});
179 else
180 [leg,labelhandles,outH,outM] = find_legend_info(varargin{2});
181 end
182 return;
183 end
184
2 185 old_currfig = get(0,'CurrentFigure');
2 186 if ~isempty(old_currfig)
2 187 old_currax = get(old_currfig,'CurrentAxes');
0.01 2 188 end
189
2 190 arg = 1;
191
192 % GET AXES FROM INPUTS
2 193 if narg > 0 && ~isempty(varargin{1}) && ...
194 length(varargin{1})==1 && ...
195 ishandle(varargin{1}) && ...
196 ~isa(varargin{1},'scribe.legendinfo') && ...
197 strcmp(get(varargin{1}(1),'type'),'axes') % legend(ax,...)
198 ha = varargin{1}(1);
199 arg = arg + 1;
2 200 elseif narg > 0 && ~ischar(varargin{1}) && ...
201 ~isempty(varargin{1}) && ...
202 all(ishandle(varargin{1})) && ...
203 ~any(isa(varargin{1},'scribe.legendinfo')) % legend(children,strings,...)
204 ha = ancestor(varargin{1}(1),'axes');
205 if isempty(ha)
206 error(id('InvalidPeerParameter'),...
207 'Handle must be an axes or child of an axes.');
208 end
2 209 else
2 210 ha = gca;
2 211 end
212
213 % LOOK FOR -DEFAULTSTRINGS option flag
2 214 dfltstrings=false;
2 215 if narg >= arg && all(ischar(varargin{arg})) && ...
216 all(strcmpi(varargin{arg},'-defaultstrings'))
217 dfltstrings=true;
218 arg = arg + 1;
219 end
220
221 % if axes is a legend use its plotaxes
0.01 2 222 h = handle(ha);
0.01 2 223 if isa(h,'scribe.colorbar') || isa(h,'scribe.legend');
224 ha = double(h.axes);
225 end
2 226 h = [];
227
228 % PROCESS REMAINING INPUTS
2 229 msg = '';
2 230 if narg < arg % legend
231 if nargout<=1, % h = legend or legend with no outputs
232 l = find_legend(ha);
233 if isempty(l) && dfltstrings
234 [l,msg]=make_legend(ha,{});
235 end
236 if nargout == 1, leg = l; end
237 else % [h,objh,...] = legend
238 [leg,labelhandles,outH,outM] = find_legend_info(ha);
239 if isempty(leg) && dfltstrings
240 [h,msg] = make_legend(ha,{}); %#ok
241 [leg,labelhandles,outH,outM] = find_legend_info(ha);
242 end
243 end
244 if ~isempty(msg)
245 warning(msg.identifier,msg.message);
246 end
247 return;
2 248 elseif narg >= arg && ischar(varargin{arg})
2 249 if strcmpi(varargin{arg},'off') || strcmpi(varargin{arg},'DeleteLegend')
250 delete_legend(find_legend(ha));
2 251 elseif strcmpi(varargin{arg},'resizelegend')
252 % do nothing. there is no need for this call, but it exists in old
253 % code that was needed when legend did not have listeners to keep
254 % itself positioned (prior to R14).
2 255 elseif strcmpi(varargin{arg},'toggle')
256 l=find_legend(ha);
257 if isempty(l) || strcmpi(get(l,'Visible'),'off')
258 legend(ha,'show');
259 else
260 legend(ha,'hide');
261 end
2 262 elseif strcmpi(varargin{arg},'show')
263 l=find_legend(ha);
264 if isempty(l)
265 [h,msg] = make_legend(ha,varargin(arg+1:end));
266 else
267 set(l,'Visible','on');
268 end
2 269 elseif strcmpi(varargin{arg},'hide')
270 l=find_legend(ha);
271 if ~isempty(l)
272 set(l,'Visible','off');
273 end
2 274 elseif strcmpi(varargin{arg},'boxon')
275 l=handle(find_legend(ha));
276 if ~isempty(l)
277 set(l,'Visible','on');
278 end
2 279 elseif strcmpi(varargin{arg},'boxoff')
280 lh=handle(find_legend(ha));
281 if ~isempty(lh)
282 lh.ObserveStyle='off';
283 set(lh,'Visible','off');
284 lh.ObserveStyle='on';
285 end
2 286 else
0.88 2 287 [h,msg] = make_legend(ha,varargin(arg:end));
2 288 end
289 else % narg > 1
290 [h,msg] = make_legend(ha,varargin(arg:end));
291 end
2 292 if ~isempty(msg)
293 if isstruct(msg)
294 warning(msg.identifier,msg.message);
295 else
296 warning(msg); %#ok
297 end
298 end
299
300 % PROCESS OUTPUTS
2 301 if nargout==0
302 elseif nargout==1
303 if isempty(h)
304 leg = find_legend(ha);
305 else
306 leg = h;
307 end
308 elseif nargout==2
309 [leg,labelhandles] = find_legend_labelhandles(ha);
310 elseif nargout<=4
311 [leg,labelhandles,outH,outM] = find_legend_info(ha);
312 elseif nargout>4
313 error(id('BadNumberOfOutputs'),'Must have 0,1,2,3 or 4 outputs.');
314 end
315
316 % before going, be sure to reset current figure and axes
2 317 if ~isempty(old_currfig) && ishandle(old_currfig) && ~strcmpi(get(old_currfig,'beingdeleted'),'on')
2 318 set(0,'CurrentFigure',old_currfig);
2 319 if ~isempty(old_currax) && ishandle(old_currax) && ~strcmpi(get(old_currax,'beingdeleted'),'on')
2 320 set(old_currfig,'CurrentAxes',old_currax);
2 321 end
2 322 end
2 323 end

Other subfunctions in this file are not included in this listing.