5837
|
1 ## Copyright (C) 1996 John W. Eaton |
|
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 2, or (at your option) |
|
8 ## 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, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
5910
|
21 ## @deftypefn {Function File} {} plot3 (@var{args}) |
6895
|
22 ## Produce three-dimensional plots. Many different combinations of |
|
23 ## arguments are possible. The simplest form is |
5837
|
24 ## |
|
25 ## @example |
|
26 ## plot3 (@var{x}, @var{y}, @var{z}) |
|
27 ## @end example |
|
28 ## |
|
29 ## @noindent |
6895
|
30 ## in which the arguments are taken to be the vertices of the points to |
|
31 ## be plotted in three dimensions. If all arguments are vectors of the |
|
32 ## same length, then a single continuous line is drawn. If all arguments |
|
33 ## are matrices, then each column of the matrices is treated as a |
|
34 ## seperate line. No attempt is made to transpose the arguments to make |
|
35 ## the number of rows match. |
5837
|
36 ## |
6895
|
37 ## If only two arguments are given, as |
5910
|
38 ## |
|
39 ## @example |
|
40 ## plot3 (@var{x}, @var{c}) |
|
41 ## @end example |
|
42 ## |
6895
|
43 ## @noindent |
|
44 ## the real and imaginary parts of the second argument are used |
|
45 ## as the @var{y} and @var{z} coordinates, respectively. |
5910
|
46 ## |
|
47 ## If only one argument is given, as |
|
48 ## |
|
49 ## @example |
|
50 ## plot3 (@var{c}) |
|
51 ## @end example |
|
52 ## |
6895
|
53 ## @noindent |
5910
|
54 ## the real and imaginary parts of the argument are used as the @var{y} |
|
55 ## and @var{z} values, and they are plotted versus their index. |
|
56 ## |
6895
|
57 ## Arguments may also be given in groups of three as |
5837
|
58 ## |
|
59 ## @example |
6146
|
60 ## plot3 (@var{x1}, @var{y1}, @var{z1}, @var{x2}, @var{y2}, @var{z2}, @dots{}) |
5837
|
61 ## @end example |
|
62 ## |
|
63 ## @noindent |
6895
|
64 ## in which each set of three arguments is treated as a seperate line or |
5910
|
65 ## set of lines in three dimensions. |
|
66 ## |
6895
|
67 ## To plot multiple one- or two-argument groups, separate each group |
|
68 ## with an empty format string, as |
5910
|
69 ## |
|
70 ## @example |
6895
|
71 ## plot3 (@var{x1}, @var{c1}, "", @var{c2}, "", @dots{}) |
5910
|
72 ## @end example |
5837
|
73 ## |
6895
|
74 ## An example of the use of @code{plot3} is |
5837
|
75 ## |
|
76 ## @example |
|
77 ## @group |
|
78 ## z = [0:0.05:5]; |
6895
|
79 ## plot3 (cos(2*pi*z), sin(2*pi*z), z, ";helix;"); |
|
80 ## plot3 (z, exp(2i*pi*z), ";complex sinusoid;"); |
5837
|
81 ## @end group |
|
82 ## @end example |
6895
|
83 ## @seealso{plot} |
5837
|
84 ## @end deftypefn |
|
85 |
|
86 ## Author: Paul Kienzle |
|
87 ## (modified from __plt__.m) |
|
88 |
6302
|
89 function retval = plot3 (varargin) |
5837
|
90 |
6560
|
91 newplot (); |
|
92 |
6257
|
93 x_set = 0; |
|
94 y_set = 0; |
|
95 z_set = 0; |
6459
|
96 property_set = 0; |
|
97 fmt_set = 0; |
|
98 properties = {}; |
5837
|
99 |
6302
|
100 idx = 0; |
|
101 |
6257
|
102 ## Gather arguments, decode format, and plot lines. |
6459
|
103 arg = 0; |
|
104 while (arg++ < nargin) |
6257
|
105 new = varargin{arg}; |
6459
|
106 new_cell = varargin(arg); |
|
107 |
|
108 if (property_set) |
|
109 properties = [properties, new_cell]; |
|
110 property_set = 0; |
|
111 continue; |
|
112 endif |
6004
|
113 |
6257
|
114 if (ischar (new)) |
|
115 if (! z_set) |
|
116 if (! y_set) |
|
117 if (! x_set) |
|
118 error ("plot3: needs x, [ y, [ z ] ]"); |
6004
|
119 else |
6257
|
120 z = imag (x); |
|
121 y = real (x); |
|
122 y_set = 1; |
|
123 z_set = 1; |
|
124 if (rows(x) > 1) |
|
125 x = repmat ((1:rows(x))', 1, columns(x)); |
|
126 else |
|
127 x = 1:columns(x); |
|
128 endif |
6004
|
129 endif |
6257
|
130 else |
|
131 z = imag (y); |
|
132 y = real (y); |
|
133 z_set = 1; |
6004
|
134 endif |
5837
|
135 endif |
6459
|
136 |
|
137 if (! fmt_set) |
|
138 [options, valid] = __pltopt__ ("plot3", new, false); |
|
139 if (! valid) |
|
140 properties = [properties, new_cell]; |
|
141 property_set = 1; |
|
142 continue; |
|
143 else |
|
144 fmt_set = 1; |
|
145 while (arg < nargin && ischar (varargin{arg+1})) |
|
146 if (nargin - arg < 2) |
|
147 error ("plot3: properties must appear followed by a value"); |
|
148 endif |
|
149 properties = [properties, varargin(arg:arg+1)]; |
|
150 arg += 2; |
|
151 endwhile |
|
152 endif |
|
153 else |
|
154 properties = [properties, new_cell]; |
|
155 property_set = 1; |
|
156 continue; |
|
157 endif |
6004
|
158 |
|
159 if (isvector (x) && isvector (y)) |
|
160 if (isvector (z)) |
|
161 x = x(:); |
|
162 y = y(:); |
|
163 z = z(:); |
|
164 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
165 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
166 else |
|
167 [x, y] = meshgrid (x, y); |
|
168 endif |
|
169 endif |
|
170 |
6157
|
171 if (! size_equal (x, y) || ! size_equal (x, z)) |
6004
|
172 error ("plot3: x, y, and z must have the same shape"); |
|
173 endif |
|
174 |
6264
|
175 key = options.key; |
|
176 if (! isempty (key)) |
|
177 set (gca (), "key", "on"); |
|
178 endif |
6459
|
179 color = options.color; |
|
180 if (isempty (options.color)) |
|
181 color = __next_line_color__ (); |
|
182 endif |
6257
|
183 |
6459
|
184 tmp(++idx) = line (x(:), y(:), z(:), "keylabel", key, "color", color, |
6302
|
185 "linestyle", options.linestyle, |
6459
|
186 "marker", options.marker, properties{:}); |
6004
|
187 |
6257
|
188 x_set = 0; |
|
189 y_set = 0; |
|
190 z_set = 0; |
6459
|
191 fmt_set = 0; |
|
192 properties = {}; |
6257
|
193 elseif (! x_set) |
|
194 x = new; |
|
195 x_set = 1; |
|
196 elseif (! y_set) |
|
197 y = new; |
|
198 y_set = 1; |
|
199 elseif (! z_set) |
|
200 z = new; |
|
201 z_set = 1; |
|
202 else |
|
203 if (isvector (x) && isvector (y)) |
|
204 if (isvector (z)) |
|
205 x = x(:); |
|
206 y = y(:); |
|
207 z = z(:); |
|
208 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
209 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
210 else |
|
211 [x, y] = meshgrid (x, y); |
|
212 endif |
|
213 endif |
|
214 |
|
215 if (! size_equal (x, y) || ! size_equal (x, z)) |
|
216 error ("plot3: x, y, and z must have the same shape"); |
|
217 endif |
|
218 |
6459
|
219 options = __default_plot_options__ (); |
|
220 key = options.key; |
|
221 if (! isempty (key)) |
|
222 set (gca (), "key", "on"); |
|
223 endif |
|
224 color = options.color; |
|
225 if (isempty (color)) |
|
226 color = __next_line_color__ (); |
|
227 endif |
|
228 |
|
229 tmp(++idx) = line (x(:), y(:), z(:), "keylabel", key, "color", color, |
|
230 "linestyle", options.linestyle, |
|
231 "marker", options.marker, properties{:}); |
6257
|
232 |
|
233 x = new; |
|
234 y_set = 0; |
|
235 z_set = 0; |
6459
|
236 fmt_set = 0; |
|
237 properties = {}; |
5837
|
238 endif |
6257
|
239 |
6459
|
240 endwhile |
|
241 |
|
242 if (property_set) |
|
243 error ("plot3: properties must appear followed by a value"); |
|
244 endif |
6257
|
245 |
|
246 ## Handle last plot. |
|
247 |
|
248 if (x_set) |
|
249 if (y_set) |
|
250 if (! z_set) |
|
251 z = imag (y); |
|
252 y = real (y); |
|
253 z_set = 1; |
|
254 endif |
|
255 else |
|
256 z = imag (x); |
|
257 y = real (x); |
|
258 y_set = 1; |
|
259 z_set = 1; |
|
260 if (rows (x) > 1) |
|
261 x = repmat ((1:rows (x))', 1, columns(x)); |
|
262 else |
|
263 x = 1:columns(x); |
|
264 endif |
5837
|
265 endif |
6257
|
266 |
|
267 if (isvector (x) && isvector (y)) |
|
268 if (isvector (z)) |
|
269 x = x(:); |
|
270 y = y(:); |
|
271 z = z(:); |
|
272 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
273 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
274 else |
|
275 [x, y] = meshgrid (x, y); |
|
276 endif |
|
277 endif |
|
278 |
|
279 if (! size_equal (x, y) || ! size_equal (x, z)) |
|
280 error ("plot3: x, y, and z must have the same shape"); |
|
281 endif |
|
282 |
6459
|
283 options = __default_plot_options__ (); |
|
284 key = options.key; |
|
285 if (! isempty (key)) |
|
286 set (gca (), "key", "on"); |
|
287 endif |
|
288 color = options.color; |
|
289 if (isempty (color)) |
|
290 color = __next_line_color__ (); |
|
291 endif |
6257
|
292 |
6459
|
293 tmp(++idx) = line (x(:), y(:), z(:), "keylabel", key, "color", color, |
|
294 "linestyle", options.linestyle, |
|
295 "marker", options.marker, properties{:}); |
6257
|
296 endif |
|
297 |
|
298 set (gca (), "view", [-37.5, 30]); |
5837
|
299 |
6302
|
300 if (nargout > 0 && idx > 0) |
|
301 retval = tmp; |
|
302 endif |
|
303 |
5837
|
304 endfunction |