Mercurial > hg > octave-nkf
annotate scripts/plot/plot3.m @ 10866:045558999570
print.m: Include 'colormap' when converting RGB to mono.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sun, 08 Aug 2010 14:49:49 -0400 |
parents | 95c3e38098bf |
children | e81914f3921f |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 1996, 2006, 2007, 2008, 2009 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 |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## be plotted in three dimensions. If all arguments are vectors of the |
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
31 ## same length, then a single continuous line is drawn. If all arguments |
6895 | 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 | |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8257
diff
changeset
|
82 ## @seealso{plot, xlabel, ylabel, zlabel, title, print} |
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) | |
10549 | 115 if (! y_set) |
116 if (! x_set) | |
117 error ("plot3: needs x, [ y, [ z ] ]"); | |
118 else | |
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 | |
128 endif | |
129 else | |
130 z = imag (y); | |
131 y = real (y); | |
132 z_set = 1; | |
133 endif | |
5837 | 134 endif |
6459 | 135 |
136 if (! fmt_set) | |
10549 | 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+1:arg+2)]; | |
149 arg += 2; | |
150 endwhile | |
151 endif | |
6459 | 152 else |
10549 | 153 properties = [properties, new_cell]; |
154 property_set = 1; | |
155 continue; | |
6459 | 156 endif |
6004 | 157 |
158 if (isvector (x) && isvector (y)) | |
10549 | 159 if (isvector (z)) |
160 x = x(:); | |
161 y = y(:); | |
162 z = z(:); | |
163 elseif (length (x) == rows (z) && length (y) == columns (z)) | |
164 [x, y] = meshgrid (x, y); | |
165 else | |
166 error ("plot3: [length(x), length(y)] must match size(z)"); | |
167 endif | |
6004 | 168 endif |
169 | |
7292 | 170 if (! size_equal (x, y, z)) |
10549 | 171 error ("plot3: x, y, and z must have the same shape"); |
6004 | 172 endif |
173 | |
6264 | 174 key = options.key; |
175 if (! isempty (key)) | |
10549 | 176 set (gca (), "key", "on"); |
6264 | 177 endif |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
178 |
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
179 for i = 1 : columns (x) |
10135
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
9385
diff
changeset
|
180 linestyle = options.linestyle; |
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
9385
diff
changeset
|
181 marker = options.marker; |
10549 | 182 if (isempty (marker) && isempty (linestyle)) |
183 [linestyle, marker] = __next_line_style__ (); | |
184 endif | |
185 color = options.color; | |
186 if (isempty (options.color)) | |
187 color = __next_line_color__ (); | |
188 endif | |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
189 |
10549 | 190 tmp(++idx) = line (x(:, i), y(:, i), z(:, i), "keylabel", key, |
191 "color", color, "linestyle", linestyle, | |
192 "marker", marker, properties{:}); | |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
193 endfor |
6004 | 194 |
6257 | 195 x_set = 0; |
196 y_set = 0; | |
197 z_set = 0; | |
6459 | 198 fmt_set = 0; |
199 properties = {}; | |
6257 | 200 elseif (! x_set) |
201 x = new; | |
202 x_set = 1; | |
203 elseif (! y_set) | |
204 y = new; | |
205 y_set = 1; | |
206 elseif (! z_set) | |
207 z = new; | |
208 z_set = 1; | |
209 else | |
210 if (isvector (x) && isvector (y)) | |
10549 | 211 if (isvector (z)) |
212 x = x(:); | |
213 y = y(:); | |
214 z = z(:); | |
215 elseif (length (x) == rows (z) && length (y) == columns (z)) | |
216 [x, y] = meshgrid (x, y); | |
217 else | |
218 error ("plot3: [length(x), length(y)] must match size(z)"); | |
219 endif | |
6257 | 220 endif |
221 | |
7292 | 222 if (! size_equal (x, y, z)) |
10549 | 223 error ("plot3: x, y, and z must have the same shape"); |
6257 | 224 endif |
225 | |
6459 | 226 options = __default_plot_options__ (); |
227 key = options.key; | |
228 if (! isempty (key)) | |
10549 | 229 set (gca (), "key", "on"); |
6459 | 230 endif |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
231 |
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
232 for i = 1 : columns (x) |
10135
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
9385
diff
changeset
|
233 linestyle = options.linestyle; |
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
9385
diff
changeset
|
234 marker = options.marker; |
10549 | 235 if (isempty (marker) && isempty (linestyle)) |
236 [linestyle, marker] = __next_line_style__ (); | |
237 endif | |
238 color = options.color; | |
239 if (isempty (color)) | |
240 color = __next_line_color__ (); | |
241 endif | |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
242 |
10549 | 243 tmp(++idx) = line (x(:, i), y(:, i), z(:, i), "keylabel", key, |
244 "color", color, "linestyle", linestyle, | |
245 "marker", marker, properties{:}); | |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
246 endfor |
6257 | 247 |
248 x = new; | |
249 y_set = 0; | |
250 z_set = 0; | |
6459 | 251 fmt_set = 0; |
252 properties = {}; | |
5837 | 253 endif |
6257 | 254 |
6459 | 255 endwhile |
256 | |
257 if (property_set) | |
258 error ("plot3: properties must appear followed by a value"); | |
259 endif | |
6257 | 260 |
261 ## Handle last plot. | |
262 | |
263 if (x_set) | |
264 if (y_set) | |
265 if (! z_set) | |
10549 | 266 z = imag (y); |
267 y = real (y); | |
268 z_set = 1; | |
6257 | 269 endif |
270 else | |
271 z = imag (x); | |
272 y = real (x); | |
273 y_set = 1; | |
274 z_set = 1; | |
275 if (rows (x) > 1) | |
10549 | 276 x = repmat ((1:rows (x))', 1, columns(x)); |
6257 | 277 else |
10549 | 278 x = 1:columns(x); |
6257 | 279 endif |
5837 | 280 endif |
6257 | 281 |
282 if (isvector (x) && isvector (y)) | |
283 if (isvector (z)) | |
10549 | 284 x = x(:); |
285 y = y(:); | |
286 z = z(:); | |
6257 | 287 elseif (length (x) == rows (z) && length (y) == columns (z)) |
10549 | 288 [x, y] = meshgrid (x, y); |
6257 | 289 else |
10549 | 290 error ("plot3: [length(x), length(y)] must match size(z)"); |
6257 | 291 endif |
292 endif | |
293 | |
7292 | 294 if (! size_equal (x, y, z)) |
6257 | 295 error ("plot3: x, y, and z must have the same shape"); |
296 endif | |
297 | |
6459 | 298 options = __default_plot_options__ (); |
299 key = options.key; | |
300 if (! isempty (key)) | |
301 set (gca (), "key", "on"); | |
302 endif | |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
303 |
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
304 for i = 1 : columns (x) |
10135
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
9385
diff
changeset
|
305 linestyle = options.linestyle; |
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
9385
diff
changeset
|
306 marker = options.marker; |
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
9385
diff
changeset
|
307 if (isempty (marker) && isempty (linestyle)) |
10549 | 308 [linestyle, marker] = __next_line_style__ (); |
10135
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
9385
diff
changeset
|
309 endif |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
310 color = options.color; |
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
311 if (isempty (color)) |
10549 | 312 color = __next_line_color__ (); |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
313 endif |
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
314 |
8257 | 315 tmp(++idx) = line (x(:, i), y(:, i), z(:, i), "keylabel", key, |
10549 | 316 "color", color, "linestyle", linestyle, |
317 "marker", marker, properties{:}); | |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
318 endfor |
6257 | 319 endif |
320 | |
321 set (gca (), "view", [-37.5, 30]); | |
5837 | 322 |
6302 | 323 if (nargout > 0 && idx > 0) |
324 retval = tmp; | |
325 endif | |
326 | |
5837 | 327 endfunction |
7245 | 328 |
329 %!demo | |
330 %! z = [0:0.05:5]; | |
331 %! plot3 (cos(2*pi*z), sin(2*pi*z), z, ";helix;"); | |
332 %! plot3 (z, exp(2i*pi*z), ";complex sinusoid;"); |