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