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 ## |
|
59 ## An optional format argument can be given as |
|
60 ## |
|
61 ## @example |
|
62 ## plot3 (@var{x}, @var{y}, @var{y}, @var{fmt}) |
|
63 ## @end example |
|
64 ## |
|
65 ## If the @var{fmt} argument is supplied, it is interpreted as |
|
66 ## follows. If @var{fmt} is missing, the default gnuplot line style |
|
67 ## is assumed. |
|
68 ## |
|
69 ## @table @samp |
|
70 ## @item - |
|
71 ## Set lines plot style (default). |
|
72 ## |
|
73 ## @item . |
|
74 ## Set dots plot style. |
|
75 ## |
|
76 ## @item @@ |
|
77 ## Set points plot style. |
|
78 ## |
|
79 ## @item -@@ |
|
80 ## Set linespoints plot style. |
|
81 ## |
|
82 ## @item ^ |
|
83 ## Set impulses plot style. |
|
84 ## |
|
85 ## @item L |
|
86 ## Set steps plot style. |
|
87 ## |
|
88 ## @item @var{n} |
|
89 ## Interpreted as the plot color if @var{n} is an integer in the range 1 to |
|
90 ## 6. |
|
91 ## |
|
92 ## @item @var{nm} |
|
93 ## If @var{nm} is a two digit integer and @var{m} is an integer in the |
|
94 ## range 1 to 6, @var{m} is interpreted as the point style. This is only |
|
95 ## valid in combination with the @code{@@} or @code{-@@} specifiers. |
|
96 ## |
|
97 ## @item @var{c} |
|
98 ## If @var{c} is one of @code{"k"}, @code{"r"}, @code{"g"}, @code{"b"}, |
|
99 ## @code{"m"}, @code{"c"}, or @code{"w"}, it is interpreted as the plot |
|
100 ## color (black, red, green, blue, magenta, cyan, or white). |
|
101 ## |
|
102 ## @item ";title;" |
|
103 ## Here @code{"title"} is the label for the key. |
|
104 ## |
|
105 ## @item + |
|
106 ## @itemx * |
|
107 ## @itemx o |
|
108 ## @itemx x |
|
109 ## Used in combination with the points or linespoints styles, set the point |
|
110 ## style. |
|
111 ## @end table |
|
112 ## |
|
113 ## The color line styles have the following meanings on terminals that |
|
114 ## support color. |
|
115 ## |
|
116 ## @example |
|
117 ## Number Gnuplot colors (lines)points style |
|
118 ## 1 red * |
|
119 ## 2 green + |
|
120 ## 3 blue o |
|
121 ## 4 magenta x |
|
122 ## 5 cyan house |
|
123 ## 6 brown there exists |
|
124 ## @end example |
|
125 ## |
|
126 ## The @var{fmt} argument can also be used to assign key titles. |
|
127 ## To do so, include the desired title between semi-colons after the |
|
128 ## formatting sequence described above, e.g. "+3;Key Title;" |
|
129 ## Note that the last semi-colon is required and will generate an error if |
|
130 ## it is left out. |
|
131 ## |
|
132 ## Arguments can also be given in groups of three as |
|
133 ## |
|
134 ## @example |
|
135 ## plot3 (@var{x1}, @var{y1}, @var{y1}, @var{x2}, @var{y2}, @var{y2}, @dots{}) |
|
136 ## @end example |
|
137 ## |
|
138 ## @noindent |
5910
|
139 ## where each set of three arguments is treated as a seperate line or |
|
140 ## set of lines in three dimensions. |
|
141 ## |
|
142 ## To plot multiple one- or two-argument groups, separate each group with an |
|
143 ## empty format string, as |
|
144 ## |
|
145 ## @example |
|
146 ## plot3 (@var{x1}, @var{c1}, '', @var{c2}, '', @dots{}) |
|
147 ## @end example |
5837
|
148 ## |
|
149 ## An example of the use of plot3 is |
|
150 ## |
|
151 ## @example |
|
152 ## @group |
|
153 ## z = [0:0.05:5]; |
|
154 ## plot3(cos(2*pi*z), sin(2*pi*z), z, ";helix;"); |
5910
|
155 ## plot3(z, exp(2i*pi*z), ";complex sinusoid;"); |
5837
|
156 ## @end group |
|
157 ## @end example |
|
158 ## |
|
159 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, __pltopt__ |
|
160 ## bar, stairs, errorbar, replot, xlabel, ylabel, title, print} |
|
161 ## @end deftypefn |
|
162 |
|
163 ## Author: Paul Kienzle |
|
164 ## (modified from __plt__.m) |
|
165 |
5838
|
166 function plot3 (varargin) |
5837
|
167 |
|
168 hold_state = ishold (); |
|
169 |
|
170 unwind_protect |
|
171 |
|
172 x_set = 0; |
|
173 y_set = 0; |
|
174 z_set = 0; |
|
175 |
|
176 ## Gather arguments, decode format, and plot lines. |
5838
|
177 for arg = 1:nargin |
5837
|
178 new = varargin{arg}; |
|
179 |
|
180 if (ischar (new)) |
|
181 if (! z_set) |
5910
|
182 if (! y_set) |
|
183 if (! x_set) |
|
184 error ("plot3: needs x, [ y, [ z ] ]"); |
|
185 else |
|
186 z = imag (x); |
|
187 y = real (x); |
|
188 y_set = 1; |
|
189 z_set = 1; |
|
190 if (rows(x) > 1) |
|
191 x = repmat ((1:rows(x))', 1, columns(x)); |
|
192 else |
|
193 x = 1:columns(x); |
|
194 endif |
|
195 endif |
|
196 else |
|
197 z = imag (y); |
|
198 y = real (y); |
|
199 z_set = 1; |
|
200 endif |
5837
|
201 endif |
|
202 fmt = __pltopt__ ("plot3", new); |
6004
|
203 |
|
204 if (isvector (x) && isvector (y)) |
|
205 if (isvector (z)) |
|
206 x = x(:); |
|
207 y = y(:); |
|
208 z = z(:); |
|
209 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
210 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
211 else |
|
212 [x, y] = meshgrid (x, y); |
|
213 endif |
|
214 endif |
|
215 |
|
216 if (any (size (x) != size (y)) || any (size (x) != size (z))) |
|
217 error ("plot3: x, y, and z must have the same shape"); |
|
218 endif |
|
219 |
|
220 unwind_protect |
|
221 __gnuplot_raw__ ("set nohidden3d;\n") |
|
222 __gnuplot_set__ parametric; |
|
223 |
|
224 __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... |
|
225 ([y; NaN*ones(1,size(y,2))])(:), ... |
|
226 ([z; NaN*ones(1,size(z,2))])(:)], "", fmt); |
|
227 |
|
228 unwind_protect_cleanup |
|
229 __gnuplot_set__ noparametric; |
|
230 end_unwind_protect |
|
231 |
5910
|
232 hold ("on"); |
5837
|
233 x_set = 0; |
|
234 y_set = 0; |
|
235 z_set = 0; |
5838
|
236 elseif (! x_set) |
5837
|
237 x = new; |
|
238 x_set = 1; |
5838
|
239 elseif (! y_set) |
5837
|
240 y = new; |
|
241 y_set = 1; |
5838
|
242 elseif (! z_set) |
5837
|
243 z = new; |
|
244 z_set = 1; |
|
245 else |
6004
|
246 if (isvector (x) && isvector (y)) |
|
247 if (isvector (z)) |
|
248 x = x(:); |
|
249 y = y(:); |
|
250 z = z(:); |
|
251 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
252 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
253 else |
|
254 [x, y] = meshgrid (x, y); |
|
255 endif |
|
256 endif |
|
257 |
|
258 if (any (size (x) != size (y)) || any (size (x) != size (z))) |
|
259 error ("plot3: x, y, and z must have the same shape"); |
|
260 endif |
|
261 |
|
262 unwind_protect |
|
263 __gnuplot_raw__ ("set nohidden3d;\n") |
|
264 __gnuplot_set__ parametric; |
|
265 |
|
266 __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... |
|
267 ([y; NaN*ones(1,size(y,2))])(:), ... |
|
268 ([z; NaN*ones(1,size(z,2))])(:)]); |
|
269 |
|
270 unwind_protect_cleanup |
|
271 __gnuplot_set__ noparametric; |
|
272 end_unwind_protect |
|
273 |
5910
|
274 hold ("on"); |
5837
|
275 x = new; |
|
276 y_set = 0; |
|
277 z_set = 0; |
|
278 endif |
|
279 |
|
280 endfor |
|
281 |
|
282 ## Handle last plot. |
|
283 |
5910
|
284 if (x_set) |
|
285 if (y_set) |
|
286 if (! z_set) |
|
287 z = imag (y); |
|
288 y = real (y); |
|
289 z_set = 1; |
|
290 endif |
|
291 else |
|
292 z = imag (x); |
|
293 y = real (x); |
|
294 y_set = 1; |
|
295 z_set = 1; |
|
296 if (rows (x) > 1) |
|
297 x = repmat ((1:rows (x))', 1, columns(x)); |
|
298 else |
|
299 x = 1:columns(x); |
|
300 endif |
|
301 endif |
6004
|
302 |
|
303 if (isvector (x) && isvector (y)) |
|
304 if (isvector (z)) |
|
305 x = x(:); |
|
306 y = y(:); |
|
307 z = z(:); |
|
308 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
309 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
310 else |
|
311 [x, y] = meshgrid (x, y); |
|
312 endif |
|
313 endif |
|
314 |
|
315 if (any (size (x) != size (y)) || any (size (x) != size (z))) |
|
316 error ("plot3: x, y, and z must have the same shape"); |
|
317 endif |
|
318 |
|
319 unwind_protect |
|
320 __gnuplot_raw__ ("set nohidden3d;\n") |
|
321 __gnuplot_set__ parametric; |
|
322 |
|
323 __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... |
|
324 ([y; NaN*ones(1,size(y,2))])(:), ... |
|
325 ([z; NaN*ones(1,size(z,2))])(:)]); |
|
326 unwind_protect_cleanup |
|
327 __gnuplot_set__ noparametric; |
|
328 end_unwind_protect |
5837
|
329 endif |
|
330 |
|
331 unwind_protect_cleanup |
|
332 |
|
333 if (! hold_state) |
5910
|
334 hold ("off"); |
5837
|
335 endif |
|
336 |
|
337 end_unwind_protect |
|
338 |
|
339 endfunction |