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; |
5837
|
101 |
6302
|
102 idx = 0; |
|
103 |
6257
|
104 ## Gather arguments, decode format, and plot lines. |
|
105 for arg = 1:nargin |
|
106 new = varargin{arg}; |
6004
|
107 |
6257
|
108 if (ischar (new)) |
|
109 if (! z_set) |
|
110 if (! y_set) |
|
111 if (! x_set) |
|
112 error ("plot3: needs x, [ y, [ z ] ]"); |
6004
|
113 else |
6257
|
114 z = imag (x); |
|
115 y = real (x); |
|
116 y_set = 1; |
|
117 z_set = 1; |
|
118 if (rows(x) > 1) |
|
119 x = repmat ((1:rows(x))', 1, columns(x)); |
|
120 else |
|
121 x = 1:columns(x); |
|
122 endif |
6004
|
123 endif |
6257
|
124 else |
|
125 z = imag (y); |
|
126 y = real (y); |
|
127 z_set = 1; |
6004
|
128 endif |
5837
|
129 endif |
6264
|
130 options = __pltopt__ ("plot3", new); |
6004
|
131 |
|
132 if (isvector (x) && isvector (y)) |
|
133 if (isvector (z)) |
|
134 x = x(:); |
|
135 y = y(:); |
|
136 z = z(:); |
|
137 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
138 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
139 else |
|
140 [x, y] = meshgrid (x, y); |
|
141 endif |
|
142 endif |
|
143 |
6157
|
144 if (! size_equal (x, y) || ! size_equal (x, z)) |
6004
|
145 error ("plot3: x, y, and z must have the same shape"); |
|
146 endif |
|
147 |
6264
|
148 key = options.key; |
|
149 if (! isempty (key)) |
|
150 set (gca (), "key", "on"); |
|
151 endif |
6257
|
152 |
6302
|
153 tmp(++idx) = line (x(:), y(:), z(:), "keylabel", key, |
|
154 "color", options.color, |
|
155 "linestyle", options.linestyle, |
|
156 "marker", options.marker); |
6004
|
157 |
6257
|
158 x_set = 0; |
|
159 y_set = 0; |
|
160 z_set = 0; |
|
161 elseif (! x_set) |
|
162 x = new; |
|
163 x_set = 1; |
|
164 elseif (! y_set) |
|
165 y = new; |
|
166 y_set = 1; |
|
167 elseif (! z_set) |
|
168 z = new; |
|
169 z_set = 1; |
|
170 else |
|
171 if (isvector (x) && isvector (y)) |
|
172 if (isvector (z)) |
|
173 x = x(:); |
|
174 y = y(:); |
|
175 z = z(:); |
|
176 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
177 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
178 else |
|
179 [x, y] = meshgrid (x, y); |
|
180 endif |
|
181 endif |
|
182 |
|
183 if (! size_equal (x, y) || ! size_equal (x, z)) |
|
184 error ("plot3: x, y, and z must have the same shape"); |
|
185 endif |
|
186 |
6302
|
187 tmp(++idx) = line (x(:), y(:), z(:)); |
6257
|
188 |
|
189 x = new; |
|
190 y_set = 0; |
|
191 z_set = 0; |
5837
|
192 endif |
6257
|
193 |
|
194 endfor |
|
195 |
|
196 ## Handle last plot. |
|
197 |
|
198 if (x_set) |
|
199 if (y_set) |
|
200 if (! z_set) |
|
201 z = imag (y); |
|
202 y = real (y); |
|
203 z_set = 1; |
|
204 endif |
|
205 else |
|
206 z = imag (x); |
|
207 y = real (x); |
|
208 y_set = 1; |
|
209 z_set = 1; |
|
210 if (rows (x) > 1) |
|
211 x = repmat ((1:rows (x))', 1, columns(x)); |
|
212 else |
|
213 x = 1:columns(x); |
|
214 endif |
5837
|
215 endif |
6257
|
216 |
|
217 if (isvector (x) && isvector (y)) |
|
218 if (isvector (z)) |
|
219 x = x(:); |
|
220 y = y(:); |
|
221 z = z(:); |
|
222 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
223 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
224 else |
|
225 [x, y] = meshgrid (x, y); |
|
226 endif |
|
227 endif |
|
228 |
|
229 if (! size_equal (x, y) || ! size_equal (x, z)) |
|
230 error ("plot3: x, y, and z must have the same shape"); |
|
231 endif |
|
232 |
6302
|
233 tmp(++idx) = line (x(:), y(:), z(:)); |
6257
|
234 |
|
235 endif |
|
236 |
|
237 set (gca (), "view", [-37.5, 30]); |
5837
|
238 |
6302
|
239 if (nargout > 0 && idx > 0) |
|
240 retval = tmp; |
|
241 endif |
|
242 |
5837
|
243 endfunction |