7217
|
1 ## Copyright (C) 2006, 2007 Michel D. Schmid |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
|
19 ## Undocumented internal function |
|
20 |
|
21 ## Author: Michel D. Schmid <michaelschmid@users.sourceforge.net> |
|
22 ## Adapted-by: jwe |
|
23 |
|
24 function h = __stem__ (have_z, varargin) |
|
25 |
|
26 [ax, varargin, nargin] = __plt_get_axis_arg__ ("stem", varargin{:}); |
|
27 |
|
28 if (nargin < 1 || nargin > 4) |
|
29 print_usage (); |
|
30 endif |
|
31 |
|
32 [x, y, z, dofill, lc, ls, mc, ms] = check_stem_arg (have_z, varargin{:}); |
|
33 |
|
34 if (dofill) |
|
35 fc = mc; |
|
36 else |
|
37 fc = "none"; |
|
38 endif |
|
39 |
|
40 newplot (); |
|
41 nx = numel (x); |
|
42 xt = x(:)'; |
|
43 xt = [xt; xt; NaN(1, nx)](:); |
|
44 if (have_z) |
|
45 yt = y(:)'; |
|
46 yt = [yt; yt; NaN(1, nx)](:); |
|
47 zt = z(:)'; |
|
48 zt = [zeros(1, nx); zt; NaN(1, nx)](:); |
|
49 else |
|
50 yt = y(:)'; |
|
51 yt = [zeros(1, nx); yt; NaN(1, nx)](:); |
|
52 endif |
|
53 |
|
54 oldax = gca (); |
|
55 unwind_protect |
|
56 axes (ax); |
|
57 |
|
58 if (have_z) |
|
59 h_stems = plot3 (xt, yt, zt, "color", lc, "linestyle", ls, |
|
60 x, y, z, "color", mc, "marker", ms, "linestyle", "", |
|
61 "markerfacecolor", fc); |
|
62 |
|
63 h_baseline = []; |
|
64 else |
|
65 h_stems = plot (xt, yt, "color", lc, "linestyle", ls, |
|
66 x, y, "color", mc, "marker", ms, "linestyle", "", |
|
67 "markerfacecolor", fc); |
|
68 |
|
69 ## Must draw the plot first to get proper x limits. |
|
70 drawnow(); |
|
71 x_axis_range = get (gca, "xlim"); |
|
72 h_baseline = line (x_axis_range, [0, 0], "color", [0, 0, 0]); |
|
73 endif |
|
74 unwind_protect_cleanup |
|
75 axes (oldax); |
|
76 end_unwind_protect |
|
77 |
|
78 h = [h_stems; h_baseline]; |
|
79 |
|
80 endfunction |
|
81 |
|
82 function [x, y, z, dofill, lc, ls, mc, ms] = check_stem_arg (have_z, varargin) |
|
83 |
|
84 ## set specifiers to default values |
|
85 [lc, ls, mc, ms] = set_default_values (); |
|
86 dofill = 0; |
|
87 fill_2 = 0; |
|
88 linespec_2 = 0; |
|
89 z = []; |
|
90 |
|
91 ## check input arguments |
|
92 if (nargin == 2) |
|
93 if (have_z) |
|
94 z = varargin{1}; |
|
95 x = 1 : rows (z); |
|
96 y = 1 : columns (z); |
|
97 else |
|
98 y = varargin{1}; |
|
99 if (isvector (y)) |
|
100 x = 1:length(y); |
|
101 elseif (ismatrix (y)) |
|
102 x = 1:rows(y); |
|
103 else |
|
104 error ("stem: Y must be a matrix"); |
|
105 endif # in each case, x & y will be defined |
|
106 endif |
|
107 elseif (nargin == 3) |
|
108 ## several possibilities |
|
109 ## 1. the real y data |
|
110 ## 2. 'fill' |
|
111 ## 3. line spec |
|
112 if (ischar (varargin{2})) |
|
113 ## only 2. or 3. possible |
|
114 if (strcmp ("fill", varargin{2})) |
|
115 dofill = 1; |
|
116 else |
|
117 ## parse the linespec |
|
118 [lc, ls, mc, ms] = stem_line_spec (varargin{2}); |
|
119 endif |
|
120 if (have_z) |
|
121 z = varargin{1}; |
|
122 x = 1 : rows (z); |
|
123 y = 1 : columns (z); |
|
124 else |
|
125 y = varargin{1}; |
|
126 if (isvector (y)) |
|
127 x = 1:length(y); |
|
128 elseif (ismatrix (y)) |
|
129 x = 1:rows(y); |
|
130 else |
|
131 error ("stem: Y must be a matrix"); |
|
132 endif # in each case, x & y will be defined |
|
133 endif |
|
134 else |
|
135 if (have_z) |
|
136 error ("stem3: must define X, Y and Z"); |
|
137 else |
|
138 ## must be the real y data |
|
139 x = varargin{1}; |
|
140 y = varargin{2}; |
|
141 if (! (ismatrix (x) && ismatrix (y))) |
|
142 error ("stem: X and Y must be matrices"); |
|
143 endif |
|
144 endif |
|
145 endif |
|
146 elseif (nargin == 4) |
|
147 ## again several possibilities |
|
148 ## arg2 1. real y |
|
149 ## arg2 2. 'fill' or linespec |
|
150 ## arg3 1. real z |
|
151 ## arg3 2. 'fill' or linespec |
|
152 if (ischar (varargin{2})) |
|
153 ## only arg2 2. / arg3 1. & arg3 3. are possible |
|
154 if (strcmp ("fill", varargin{2})) |
|
155 dofill = 1; |
|
156 fill_2 = 1; # be sure, no second "fill" is in the arguments |
|
157 else |
|
158 ## must be a linespec |
|
159 [lc, ls, mc, ms] = stem_line_spec (varargin{2}); |
|
160 linespec_2 = 1; |
|
161 endif |
|
162 if (have_z) |
|
163 z = varargin{1}; |
|
164 x = 1 : rows (z); |
|
165 y = 1 : columns (z); |
|
166 else |
|
167 y = varargin{1}; |
|
168 if (isvector (y)) |
|
169 x = 1:length(y); |
|
170 elseif (ismatrix (y)) |
|
171 x = 1:size(y,1); |
|
172 else |
|
173 error ("stem: Y must be a matrix"); |
|
174 endif # in each case, x & y will be defined |
|
175 endif |
|
176 else |
|
177 if (have_z) |
|
178 x = varargin{1}; |
|
179 y = varargin{2}; |
|
180 z = varargin{3}; |
|
181 if (! (ismatrix (x) && ismatrix (y) && ismatrix (z))) |
|
182 error ("stem3: X, Y and Z must be matrices"); |
|
183 endif |
|
184 else |
|
185 ## must be the real y data |
|
186 x = varargin{1}; |
|
187 y = varargin{2}; |
|
188 if (! (ismatrix (x) && ismatrix (y))) |
|
189 error ("stem: X and Y must be matrices"); |
|
190 endif |
|
191 endif |
|
192 endif # if ischar(varargin{2}) |
|
193 if (! have_z) |
|
194 ## varargin{3} must be char... |
|
195 ## check for "fill" .. |
|
196 if (strcmp ("fill", varargin{3}) & fill_2) |
|
197 error ("stem:check_stem_arg: duplicate fill argument"); |
|
198 elseif (strcmp("fill", varargin{3}) & linespec_2) |
|
199 ## must be "fill" |
|
200 dofill = 1; |
|
201 fill_2 = 1; |
|
202 elseif (strcmp ("fill", varargin{3}) & ! linespec_2) |
|
203 ## must be "fill" |
|
204 dofill = 1; |
|
205 fill_2 = 1; |
|
206 elseif (! linespec_2) |
|
207 ## must be linespec |
|
208 [lc, ls, mc, ms] = stem_line_spec (varargin{3}); |
|
209 linespec_2 = 1; |
|
210 endif |
|
211 endif |
|
212 elseif (nargin == 5) |
|
213 if (have_z) |
|
214 x = varargin{1}; |
|
215 y = varargin{2}; |
|
216 z = varargin{3}; |
|
217 if (! (ismatrix (x) && ismatrix (y) && ismatrix (z))) |
|
218 error ("stem3: X, Y and Z must be matrices"); |
|
219 endif |
|
220 else |
|
221 x = varargin{1}; |
|
222 y = varargin{2}; |
|
223 if (! (ismatrix (x) && ismatrix (y))) |
|
224 error ("X and Y must be matrices"); |
|
225 endif |
|
226 endif |
|
227 |
|
228 if (! have_z) |
|
229 if (strcmp ("fill", varargin{3})) |
|
230 dofill = 1; |
|
231 fill_2 = 1; # be sure, no second "fill" is in the arguments |
|
232 else |
|
233 ## must be a linespec |
|
234 [lc, ls, mc, ms] = stem_line_spec (varargin{3}); |
|
235 linespec_2 = 1; |
|
236 endif |
|
237 endif |
|
238 |
|
239 ## check for "fill" .. |
|
240 if (strcmp ("fill", varargin{4}) & fill_2) |
|
241 error ("stem:check_stem_arg: duplicate fill argument"); |
|
242 elseif (strcmp ("fill", varargin{4}) & linespec_2) |
|
243 ## must be "fill" |
|
244 dofill = 1; |
|
245 fill_2 = 1; |
|
246 elseif (! strcmp ("fill", varargin{4}) & ! linespec_2) |
|
247 ## must be linespec |
|
248 [lc, ls, mc, ms] = stem_line_spec (varargin{4}); |
|
249 linespec_2 = 1; |
|
250 endif |
|
251 elseif (nargin == 6 && have_z) |
|
252 x = varargin{1}; |
|
253 y = varargin{2}; |
|
254 z = varargin{3}; |
|
255 if (! (ismatrix (x) && ismatrix (y) && ismatrix (z))) |
|
256 error ("stem3: X, Y and Z must be matrices"); |
|
257 endif |
|
258 |
|
259 if (strcmp ("fill", varargin{4})) |
|
260 dofill = 1; |
|
261 fill_2 = 1; # be sure, no second "fill" is in the arguments |
|
262 else |
|
263 ## must be a linespec |
|
264 [lc, ls, mc, ms] = stem_line_spec (varargin{4}); |
|
265 linespec_2 = 1; |
|
266 endif |
|
267 |
|
268 ## check for "fill" .. |
|
269 if (strcmp ("fill", varargin{5}) & fill_2) |
|
270 error ("stem3:check_stem_arg: duplicate fill argument"); |
|
271 elseif (strcmp ("fill", varargin{5}) & linespec_2) |
|
272 ## must be "fill" |
|
273 dofill = 1; |
|
274 fill_2 = 1; |
|
275 elseif (! strcmp ("fill", varargin{5}) & ! linespec_2) |
|
276 ## must be linespec |
|
277 [lc, ls, mc, ms] = stem_line_spec (varargin{5}); |
|
278 linespec_2 = 1; |
|
279 endif |
|
280 elseif (have_z) |
|
281 error ("stem3: incorrect number of arguments"); |
|
282 else |
|
283 error ("stem: incorrect number of arguments"); |
|
284 endif |
|
285 |
|
286 endfunction |
|
287 |
|
288 function [lc, ls, mc, ms] = stem_line_spec (str) |
|
289 if (! ischar (str)) |
|
290 error ("stem:stem_line_spec: wrong argument type, must be \"fill\" or a string of specifiers"); |
|
291 endif |
|
292 [lc, ls, mc, ms] = set_default_values (); |
|
293 ## Parse the line specifier string. |
|
294 cur_props = __pltopt__ ("stem", str, false); |
|
295 for i = 1:length(cur_props) |
|
296 if (isfield (cur_props(i), "color") && ! isempty (cur_props(i).color)); # means line color |
|
297 mc = lc = cur_props(i).color; |
|
298 elseif (isfield (cur_props(i), "linestyle")) |
|
299 ls = cur_props(i).linestyle; |
|
300 elseif (isfield (cur_props(i), "marker") && ! strcmp (cur_props(i).marker, "none")) |
|
301 ms = cur_props(i).marker; |
|
302 endif |
|
303 endfor |
|
304 endfunction |
|
305 |
|
306 function [lc, ls, mc, ms] = set_default_values () |
|
307 ## set default values |
|
308 mc = [1, 0, 0]; |
|
309 lc = [1, 0, 0]; |
|
310 ls = "-"; |
|
311 ms = "o"; |
|
312 endfunction |