Mercurial > hg > octave-lyh
comparison scripts/plot/private/__errplot__.m @ 13221:cc6e9425c04e stable
errorbar plots can now accept a legend key (Bug #33580).
__errplot__.m: Borrow code from __plt__ for putting legend on plot
when it is included in linespec.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 25 Sep 2011 16:24:07 -0700 |
parents | b0084095098e |
children | 72c96de7a403 |
comparison
equal
deleted
inserted
replaced
13207:88bd1d1d6657 | 13221:cc6e9425c04e |
---|---|
29 | 29 |
30 if (nargin < 4 || nargin > 8) # at least two data arguments needed | 30 if (nargin < 4 || nargin > 8) # at least two data arguments needed |
31 print_usage (); | 31 print_usage (); |
32 endif | 32 endif |
33 | 33 |
34 [fmt, key] = __pltopt__ ("__errplot__", fstr); | 34 [fmt, valid] = __pltopt__ ("__errplot__", fstr); |
35 | 35 |
36 [len, nplots] = size (varargin{1}); | 36 [len, nplots] = size (varargin{1}); |
37 h = []; | 37 h = []; |
38 | 38 |
39 for i = 1:nplots | 39 for i = 1:nplots |
72 "color", fmt.color))]; | 72 "color", fmt.color))]; |
73 | 73 |
74 switch (numel(varargin)) | 74 switch (numel(varargin)) |
75 case 2 | 75 case 2 |
76 ydata = varargin{1}(:,i); | 76 ydata = varargin{1}(:,i); |
77 xdata = 1:numel(ydata); | 77 xdata = 1:numel (ydata); |
78 if (strcmp (ifmt, "xerr") || strcmp (ifmt, "box")) | 78 if (strcmp (ifmt, "xerr") || strcmp (ifmt, "box")) |
79 xldata = varargin{2}(:,i); | 79 xldata = varargin{2}(:,i); |
80 xudata = ldata; | 80 xudata = ldata; |
81 ldata = []; | 81 ldata = []; |
82 udata = []; | 82 udata = []; |
84 ldata = varargin{2}(:,i); | 84 ldata = varargin{2}(:,i); |
85 udata = ldata; | 85 udata = ldata; |
86 xldata = []; | 86 xldata = []; |
87 xudata = []; | 87 xudata = []; |
88 else | 88 else |
89 error ("errorbar: 2 column errorplot is only valid or xerr or yerr"); | 89 error ("errorbar: 2 column errorplot is only valid for xerr or yerr"); |
90 endif | 90 endif |
91 case 3 | 91 case 3 |
92 if (strcmp (ifmt, "boxxy") || strcmp (ifmt, "xyerr")) | 92 if (strcmp (ifmt, "boxxy") || strcmp (ifmt, "xyerr")) |
93 ydata = varargin{1}(:,i); | 93 ydata = varargin{1}(:,i); |
94 xdata = 1:numel(ydata); | 94 xdata = 1:numel (ydata); |
95 xldata = varargin{2}(:,i); | 95 xldata = varargin{2}(:,i); |
96 xudata = xldata; | 96 xudata = xldata; |
97 ldata = varargin{3}(:,i); | 97 ldata = varargin{3}(:,i); |
98 udata = ldata; | 98 udata = ldata; |
99 elseif (strcmp (ifmt, "xerr") || strcmp (ifmt, "box")) | 99 elseif (strcmp (ifmt, "xerr") || strcmp (ifmt, "box")) |
144 udata = varargin{6}(:,i); | 144 udata = varargin{6}(:,i); |
145 else | 145 else |
146 error ("errorbar: error plot with 6 columns only valid for boxxy and xyerr"); | 146 error ("errorbar: error plot with 6 columns only valid for boxxy and xyerr"); |
147 endif | 147 endif |
148 otherwise | 148 otherwise |
149 error ("errorbar: error plot requires 2, 3, 4 or 6 arguments"); | 149 error ("errorbar: error plot requires 2, 3, 4, or 6 arguments"); |
150 endswitch | 150 endswitch |
151 | 151 |
152 addproperty ("xdata", hg, "data", xdata(:)); | 152 addproperty ("xdata", hg, "data", xdata(:)); |
153 addproperty ("ydata", hg, "data", ydata(:)); | 153 addproperty ("ydata", hg, "data", ydata(:)); |
154 addproperty ("ldata", hg, "data", ldata(:)); | 154 addproperty ("ldata", hg, "data", ldata(:)); |
190 addlistener (hax, "yscale", fcn); | 190 addlistener (hax, "yscale", fcn); |
191 | 191 |
192 update_data (hg, [], hl); | 192 update_data (hg, [], hl); |
193 | 193 |
194 endfor | 194 endfor |
195 | |
196 ## Process legend key | |
197 if (! isempty (fmt.key)) | |
198 hlegend = []; | |
199 fkids = get (gcf(), "children"); | |
200 for i = 1 : numel (fkids) | |
201 if (ishandle (fkids(i)) && strcmp (get (fkids(i), "type"), "axes") | |
202 && (strcmp (get (fkids(i), "tag"), "legend"))) | |
203 udata = get (fkids(i), "userdata"); | |
204 if (! isempty (intersect (udata.handle, gca ()))) | |
205 hlegend = fkids (i); | |
206 break; | |
207 endif | |
208 endif | |
209 endfor | |
210 | |
211 if (isempty (hlegend)) | |
212 hlgnd = []; | |
213 tlgnd = {}; | |
214 else | |
215 [hlgnd, tlgnd] = __getlegenddata__ (hlegend); | |
216 endif | |
217 | |
218 hlgnd(end+1) = hg; | |
219 tlgnd(end+1) = fmt.key; | |
220 | |
221 legend (gca(), hlgnd, tlgnd); | |
222 end | |
195 | 223 |
196 endfunction | 224 endfunction |
197 | 225 |
198 function [xdata, ydata] = errorbar_data (xdata, ydata, ldata, udata, | 226 function [xdata, ydata] = errorbar_data (xdata, ydata, ldata, udata, |
199 xldata, xudata, ifmt, | 227 xldata, xudata, ifmt, |
257 ydata = [y1; y2]; | 285 ydata = [y1; y2]; |
258 return | 286 return |
259 else | 287 else |
260 error ("errorbar: valid error bar types are xerr, yerr, boxxy, and xyerr"); | 288 error ("errorbar: valid error bar types are xerr, yerr, boxxy, and xyerr"); |
261 endif | 289 endif |
290 | |
262 xdata = xdata.'(:); | 291 xdata = xdata.'(:); |
263 ydata = ydata.'(:); | 292 ydata = ydata.'(:); |
293 | |
264 endfunction | 294 endfunction |
265 | 295 |
266 function update_props (hg, dummy, hl) | 296 function update_props (hg, dummy, hl) |
267 set (hl, "color", get (hg, "color"), | 297 set (hl, "color", get (hg, "color"), |
268 "linewidth", get (hg, "linewidth"));, | 298 "linewidth", get (hg, "linewidth"));, |