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