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 |
6146
|
62 ## plot3 (@var{x}, @var{y}, @var{z}, @var{fmt}) |
5837
|
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 |
6146
|
135 ## plot3 (@var{x1}, @var{y1}, @var{z1}, @var{x2}, @var{y2}, @var{z2}, @dots{}) |
5837
|
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 |
6172
|
168 __plot_globals__; |
|
169 |
|
170 cf = __current_figure__; |
|
171 mxi = __multiplot_xi__(cf); |
|
172 myi = __multiplot_yi__(cf); |
|
173 |
5837
|
174 hold_state = ishold (); |
|
175 |
|
176 unwind_protect |
|
177 |
|
178 x_set = 0; |
|
179 y_set = 0; |
|
180 z_set = 0; |
|
181 |
|
182 ## Gather arguments, decode format, and plot lines. |
5838
|
183 for arg = 1:nargin |
5837
|
184 new = varargin{arg}; |
|
185 |
|
186 if (ischar (new)) |
|
187 if (! z_set) |
5910
|
188 if (! y_set) |
|
189 if (! x_set) |
|
190 error ("plot3: needs x, [ y, [ z ] ]"); |
|
191 else |
|
192 z = imag (x); |
|
193 y = real (x); |
|
194 y_set = 1; |
|
195 z_set = 1; |
|
196 if (rows(x) > 1) |
|
197 x = repmat ((1:rows(x))', 1, columns(x)); |
|
198 else |
|
199 x = 1:columns(x); |
|
200 endif |
|
201 endif |
|
202 else |
|
203 z = imag (y); |
|
204 y = real (y); |
|
205 z_set = 1; |
|
206 endif |
5837
|
207 endif |
6146
|
208 [fmt, key] = __pltopt__ ("plot3", new); |
6004
|
209 |
|
210 if (isvector (x) && isvector (y)) |
|
211 if (isvector (z)) |
|
212 x = x(:); |
|
213 y = y(:); |
|
214 z = z(:); |
|
215 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
216 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
217 else |
|
218 [x, y] = meshgrid (x, y); |
|
219 endif |
|
220 endif |
|
221 |
6157
|
222 if (! size_equal (x, y) || ! size_equal (x, z)) |
6004
|
223 error ("plot3: x, y, and z must have the same shape"); |
|
224 endif |
|
225 |
6146
|
226 __gnuplot_raw__ ("set nohidden3d;\n") |
6004
|
227 |
6146
|
228 __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... |
|
229 ([y; NaN*ones(1,size(y,2))])(:), ... |
|
230 ([z; NaN*ones(1,size(z,2))])(:)], |
6172
|
231 true, "u($1):($2):($3)", fmt{1}, key{1}); |
6004
|
232 |
5910
|
233 hold ("on"); |
5837
|
234 x_set = 0; |
|
235 y_set = 0; |
|
236 z_set = 0; |
5838
|
237 elseif (! x_set) |
5837
|
238 x = new; |
|
239 x_set = 1; |
5838
|
240 elseif (! y_set) |
5837
|
241 y = new; |
|
242 y_set = 1; |
5838
|
243 elseif (! z_set) |
5837
|
244 z = new; |
|
245 z_set = 1; |
|
246 else |
6004
|
247 if (isvector (x) && isvector (y)) |
|
248 if (isvector (z)) |
|
249 x = x(:); |
|
250 y = y(:); |
|
251 z = z(:); |
|
252 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
253 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
254 else |
|
255 [x, y] = meshgrid (x, y); |
|
256 endif |
|
257 endif |
|
258 |
6157
|
259 if (! size_equal (x, y) || ! size_equal (x, z)) |
6004
|
260 error ("plot3: x, y, and z must have the same shape"); |
|
261 endif |
|
262 |
6146
|
263 __gnuplot_raw__ ("set nohidden3d;\n") |
6004
|
264 |
6146
|
265 __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... |
|
266 ([y; NaN*ones(1,size(y,2))])(:), ... |
6172
|
267 ([z; NaN*ones(1,size(z,2))])(:)], true); |
6004
|
268 |
5910
|
269 hold ("on"); |
5837
|
270 x = new; |
|
271 y_set = 0; |
|
272 z_set = 0; |
|
273 endif |
|
274 |
|
275 endfor |
|
276 |
|
277 ## Handle last plot. |
|
278 |
5910
|
279 if (x_set) |
|
280 if (y_set) |
|
281 if (! z_set) |
|
282 z = imag (y); |
|
283 y = real (y); |
|
284 z_set = 1; |
|
285 endif |
|
286 else |
|
287 z = imag (x); |
|
288 y = real (x); |
|
289 y_set = 1; |
|
290 z_set = 1; |
|
291 if (rows (x) > 1) |
|
292 x = repmat ((1:rows (x))', 1, columns(x)); |
|
293 else |
|
294 x = 1:columns(x); |
|
295 endif |
|
296 endif |
6004
|
297 |
|
298 if (isvector (x) && isvector (y)) |
|
299 if (isvector (z)) |
|
300 x = x(:); |
|
301 y = y(:); |
|
302 z = z(:); |
|
303 elseif (length (x) == rows (z) && length (y) == columns (z)) |
|
304 error ("plot3: [length(x), length(y)] must match size(z)"); |
|
305 else |
|
306 [x, y] = meshgrid (x, y); |
|
307 endif |
|
308 endif |
|
309 |
6157
|
310 if (! size_equal (x, y) || ! size_equal (x, z)) |
6004
|
311 error ("plot3: x, y, and z must have the same shape"); |
|
312 endif |
|
313 |
6146
|
314 __gnuplot_raw__ ("set nohidden3d;\n") |
6004
|
315 |
6146
|
316 __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... |
|
317 ([y; NaN*ones(1,size(y,2))])(:), ... |
6172
|
318 ([z; NaN*ones(1,size(z,2))])(:)], true); |
5837
|
319 endif |
|
320 |
|
321 unwind_protect_cleanup |
|
322 |
|
323 if (! hold_state) |
5910
|
324 hold ("off"); |
5837
|
325 endif |
|
326 |
|
327 end_unwind_protect |
|
328 |
|
329 endfunction |