Mercurial > hg > octave-lyh
comparison scripts/plot/legend.m @ 11246:c463aed850b0
allow legend and gcf to work when no figure is present
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 13 Nov 2010 01:25:05 -0500 |
parents | abc0c6b0a4c4 |
children | a0dfd7e8e3e2 |
comparison
equal
deleted
inserted
replaced
11245:6f5d92d55acd | 11246:c463aed850b0 |
---|---|
98 ## @end table | 98 ## @end table |
99 ## @end deftypefn | 99 ## @end deftypefn |
100 | 100 |
101 function [hlegend2, hobjects2, hplot2, text_strings2] = legend (varargin) | 101 function [hlegend2, hobjects2, hplot2, text_strings2] = legend (varargin) |
102 | 102 |
103 if (! ishandle (varargin {1}) || (strcmp (get (varargin {1}, "type"), "axes") | 103 if (nargin > 0 |
104 && ! strcmp (get (varargin {1}, "tag"), "legend"))) | 104 && (! ishandle (varargin{1}) |
105 || (strcmp (get (varargin{1}, "type"), "axes") | |
106 && ! strcmp (get (varargin{1}, "tag"), "legend")))) | |
105 [ca, varargin, nargs] = __plt_get_axis_arg__ ("legend", varargin{:}); | 107 [ca, varargin, nargs] = __plt_get_axis_arg__ ("legend", varargin{:}); |
106 fig = get (ca, "parent"); | 108 fig = get (ca, "parent"); |
107 else | 109 else |
108 fig = get (0, "currentfigure"); | 110 fig = get (0, "currentfigure"); |
109 ca = get (fig, "currentaxes"); | 111 if (isempty (fig)) |
112 fig = gcf (); | |
113 endif | |
114 ca = gca (); | |
110 endif | 115 endif |
111 | 116 |
112 if (strcmp (get (ca, "tag"), "plotyy")) | 117 if (strcmp (get (ca, "tag"), "plotyy")) |
113 plty = get(ca (strcmp (get (ca, "tag"), "plotyy")), "userdata"); | 118 plty = get(ca (strcmp (get (ca, "tag"), "plotyy")), "userdata"); |
114 if (isscalar (plty)) | 119 if (isscalar (plty)) |
116 else | 121 else |
117 ca = [ca, plty{:}]; | 122 ca = [ca, plty{:}]; |
118 endif | 123 endif |
119 endif | 124 endif |
120 | 125 |
121 if (all (ishandle (varargin{1}))) | 126 if (nargin > 0 && all (ishandle (varargin{1}))) |
122 kids = flipud (varargin{1}(:)); | 127 kids = flipud (varargin{1}(:)); |
123 varargin(1) = []; | 128 varargin(1) = []; |
124 nargs = numel (varargin); | |
125 else | 129 else |
126 kids = ca; | 130 kids = ca; |
127 kids (strcmp (get (ca, "tag"), "legend")) = []; | 131 kids (strcmp (get (ca, "tag"), "legend")) = []; |
128 if (isscalar (kids)) | 132 if (isscalar (kids)) |
129 kids = get(kids, "children")(:); | 133 kids = get(kids, "children")(:); |
130 else | 134 else |
131 kids = [get(kids, "children"){:}](:); | 135 kids = [get(kids, "children"){:}](:); |
132 endif | 136 endif |
133 endif | 137 endif |
138 nargs = numel (varargin); | |
134 nkids = numel (kids); | 139 nkids = numel (kids); |
135 | 140 |
136 orientation = "default"; | 141 orientation = "default"; |
137 position = "default"; | 142 position = "default"; |
138 show = "create"; | 143 show = "create"; |