Mercurial > hg > octave-lyh
annotate scripts/plot/surface.m @ 17059:c935a0db31c6
errorbar.m: Update to use new __plt_get_axis_arg__.
* scripts/plot/errorbar.m: Update to use new __plt_get_axis_arg__.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 24 Jul 2013 23:12:46 -0700 |
parents | 55b76fd1244b |
children | eaab03308c0b |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14001
diff
changeset
|
1 ## Copyright (C) 1993-2012 John W. Eaton |
7109 | 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 3 of the License, or (at | |
8 ## your option) 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, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) |
7175 | 21 ## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z}) |
22 ## @deftypefnx {Function File} {} surface (@var{z}, @var{c}) | |
23 ## @deftypefnx {Function File} {} surface (@var{z}) | |
24 ## @deftypefnx {Function File} {} surface (@dots{}, @var{prop}, @var{val}) | |
25 ## @deftypefnx {Function File} {} surface (@var{h}, @dots{}) | |
7650 | 26 ## @deftypefnx {Function File} {@var{h} =} surface (@dots{}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## Plot a surface graphic object given matrices @var{x}, and @var{y} from |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
28 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and |
7175 | 29 ## @var{y} coordinates of the surface. If @var{x} and @var{y} are vectors, |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
31 ## columns of @var{z} correspond to different @var{x} values and rows of |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
32 ## @var{z} correspond to different @var{y} values. If @var{x} and @var{y} |
7175 | 33 ## are missing, they are constructed from size of the matrix @var{z}. |
34 ## | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7650
diff
changeset
|
35 ## Any additional properties passed are assigned to the surface. |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13194
diff
changeset
|
36 ## |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13194
diff
changeset
|
37 ## The optional return value @var{h} is a graphics handle to the created |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13194
diff
changeset
|
38 ## surface object. |
7109 | 39 ## @seealso{surf, mesh, patch, line} |
40 ## @end deftypefn | |
41 | |
42 ## Author: jwe | |
43 | |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
44 function h = surface (varargin) |
7109 | 45 |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
46 [hax, varargin] = __plt_get_axis_arg__ ("surface", varargin{:}); |
7215 | 47 |
17040
55b76fd1244b
surface.m: Update to use new __plt_get_axis_arg__ without using "axes" function.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16986
diff
changeset
|
48 if (isempty (hax)) |
55b76fd1244b
surface.m: Update to use new __plt_get_axis_arg__ without using "axes" function.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16986
diff
changeset
|
49 hax = gca (); |
55b76fd1244b
surface.m: Update to use new __plt_get_axis_arg__ without using "axes" function.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16986
diff
changeset
|
50 endif |
55b76fd1244b
surface.m: Update to use new __plt_get_axis_arg__ without using "axes" function.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16986
diff
changeset
|
51 |
55b76fd1244b
surface.m: Update to use new __plt_get_axis_arg__ without using "axes" function.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16986
diff
changeset
|
52 [htmp, bad_usage] = __surface__ (hax, varargin{:}); |
7109 | 53 |
7207 | 54 if (bad_usage) |
55 print_usage (); | |
56 endif | |
57 | |
58 if (nargout > 0) | |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
59 h = htmp; |
7207 | 60 endif |
7216 | 61 |
7207 | 62 endfunction |
63 | |
64 function [h, bad_usage] = __surface__ (ax, varargin) | |
65 | |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
66 h = 0; |
7207 | 67 bad_usage = false; |
68 firststring = nargin; | |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
69 for i = 1 : (nargin - 1) |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
70 if (ischar (varargin{i})) |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
71 firststring = i; |
7175 | 72 break; |
7109 | 73 endif |
7175 | 74 endfor |
75 | |
76 if (firststring > 5) | |
7207 | 77 bad_usage = true; |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
78 return; |
7175 | 79 elseif (firststring == 5) |
80 x = varargin{1}; | |
81 y = varargin{2}; | |
82 z = varargin{3}; | |
83 c = varargin{4}; | |
84 | |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
85 if (iscomplex (x) || iscomplex (y) || iscomplex (z) || iscomplex (c)) |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
86 error ("mesh: X, Y, Z, C arguments must be real"); |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
87 endif |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
88 |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
89 [z_nr, z_nc] = size (z); |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
90 [c_nr, c_nc, c_np] = size (c); |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
91 if (! (z_nr == c_nr && z_nc == c_nc && (c_np == 1 || c_np == 3))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
92 error ("surface: Z and C must have the same size"); |
7109 | 93 endif |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
94 |
7109 | 95 if (isvector (x) && isvector (y) && ismatrix (z)) |
96 if (rows (z) == length (y) && columns (z) == length (x)) | |
97 x = x(:)'; | |
98 y = y(:); | |
99 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
100 error ("surface: rows (Z) must be the same as length (Y) and columns (Z) must be the same as length (X)"); |
7109 | 101 endif |
102 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | |
7292 | 103 if (! size_equal (x, y, z)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
104 error ("surface: X, Y, and Z must have the same dimensions"); |
7109 | 105 endif |
106 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
107 error ("surface: X and Y must be vectors and Z must be a matrix"); |
7109 | 108 endif |
7175 | 109 elseif (firststring == 4) |
110 x = varargin{1}; | |
111 y = varargin{2}; | |
112 z = varargin{3}; | |
113 c = z; | |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
114 |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
115 if (iscomplex (x) || iscomplex (y) || iscomplex (z)) |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
116 error ("mesh: X, Y, Z arguments must be real"); |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
117 endif |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
118 |
7175 | 119 if (isvector (x) && isvector (y) && ismatrix (z)) |
120 if (rows (z) == length (y) && columns (z) == length (x)) | |
121 x = x(:)'; | |
122 y = y(:); | |
123 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
124 error ("surface: rows (Z) must be the same as length (Y) and columns (Z) must be the same as length (X)"); |
7175 | 125 endif |
126 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | |
7292 | 127 if (! size_equal (x, y, z)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
128 error ("surface: X, Y, and Z must have the same dimensions"); |
7175 | 129 endif |
130 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
131 error ("surface: X and Y must be vectors and Z must be a matrix"); |
7175 | 132 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
133 elseif (firststring == 3) |
7208 | 134 z = varargin{1}; |
135 c = varargin{2}; | |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
136 |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
137 if (iscomplex (z) || iscomplex (c)) |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
138 error ("mesh: X, C arguments must be real"); |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
139 endif |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
140 |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
141 if (ismatrix (z) && !isvector (z) && !isscalar (z)) |
7175 | 142 [nr, nc] = size (z); |
143 x = 1:nc; | |
144 y = (1:nr)'; | |
145 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
146 error ("surface: Z argument must be a matrix"); |
7175 | 147 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
148 elseif (firststring == 2) |
7208 | 149 z = varargin{1}; |
7175 | 150 c = z; |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
151 |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
152 if (iscomplex (z)) |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
153 error ("mesh: Z argument must be real"); |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
154 endif |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
155 |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
156 if (ismatrix (z) && !isvector (z) && !isscalar (z)) |
7175 | 157 [nr, nc] = size (z); |
158 x = 1:nc; | |
159 y = (1:nr)'; | |
160 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
161 error ("surface: Z argument must be a matrix"); |
7175 | 162 endif |
13115
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
163 elseif (firststring == 1) |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
164 x = 1:3; |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
165 y = x'; |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
166 c = z = eye (3); |
7109 | 167 else |
7207 | 168 bad_usage = true; |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
169 return; |
7189 | 170 endif |
7109 | 171 |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
172 if (firststring < nargin) |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
173 other_args = varargin(firststring:end); |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
174 else |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
175 other_args = {}; # make a default surface object. |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
176 endif |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
177 h = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c, |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
178 other_args{:}); |
7109 | 179 |
16986
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
180 if (! ishold ()) |
df66488b8d43
surface.m: Validate inputs are not complex.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
181 set (ax, "view", [0, 90], "box", "off"); |
7277 | 182 endif |
7109 | 183 |
184 endfunction | |
12817
e3e6079039c6
codesprint: 2 demos for pcolor.m dummy for surface.m
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
185 |
14223
ba7a26030214
Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
186 |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13194
diff
changeset
|
187 ## Functional tests for surface() are in surf.m, surfc.m, surfl.m, and pcolor.m |
13115
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
188 %!test |
13124
2ea1658ad049
Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents:
13115
diff
changeset
|
189 %! hf = figure ("visible", "off"); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13124
diff
changeset
|
190 %! unwind_protect |
13115
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
191 %! h = surface; |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
192 %! assert (findobj (hf, "type", "surface"), h); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
193 %! assert (get (h, "xdata"), 1:3, eps); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
194 %! assert (get (h, "ydata"), (1:3)', eps); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
195 %! assert (get (h, "zdata"), eye (3)); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
196 %! assert (get (h, "cdata"), eye (3)); |
13115
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
197 %! assert (get (h, "type"), "surface"); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
198 %! assert (get (h, "linestyle"), get (0, "defaultsurfacelinestyle")); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
199 %! assert (get (h, "linewidth"), get (0, "defaultsurfacelinewidth"), eps); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
200 %! assert (get (h, "marker"), get (0, "defaultsurfacemarker")); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
201 %! assert (get (h, "markersize"), get (0, "defaultsurfacemarkersize")); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
202 %! unwind_protect_cleanup |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
203 %! close (hf); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
12819
diff
changeset
|
204 %! end_unwind_protect |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13194
diff
changeset
|
205 |