Mercurial > hg > octave-lyh
annotate scripts/plot/surfc.m @ 17052:1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
* scripts/plot/surf.m, scripts/plot/surfl.m, scripts/plot/surfnorm.m:
Update to use new __plt_get_axis_arg__. Rename h to hax. Rename tmp to htmp.
* scripts/plot/surfc.m: Check __plt_get_axis_arg__ before calling newplot.
Remove obsolete code checking for input axis handle. Use cellfun to eliminate
for loop.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Tue, 23 Jul 2013 16:26:43 +0200 |
parents | c4fa5e0b6193 |
children | a639221f9863 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 1996-2012 John W. Eaton |
7118 | 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 -*- | |
20 ## @deftypefn {Function File} {} surfc (@var{x}, @var{y}, @var{z}) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
21 ## Plot a surface and contour 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
|
22 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
23 ## @var{y} coordinates of the mesh. If @var{x} and @var{y} are vectors, |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
24 ## 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
|
25 ## columns of @var{z} correspond to different @var{x} values and rows of |
7118 | 26 ## @var{z} correspond to different @var{y} values. |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
27 ## @seealso{ezsurfc, meshgrid, surf, contour} |
7118 | 28 ## @end deftypefn |
29 | |
30 function h = surfc (varargin) | |
31 | |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
32 [hax, varargin, nargin] = __plt_get_axis_arg__ ("surfc", varargin{:}); |
7118 | 33 |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
34 if (nargin < 1) |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
35 print_usage (); |
7146 | 36 endif |
7118 | 37 |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
38 oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
39 unwind_protect |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
40 hax = newplot (hax); |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
41 |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
42 htmp = surface (hax, varargin{:}); |
7118 | 43 |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
44 set (htmp, "facecolor", "flat"); |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
45 |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
46 if (! ishold ()) |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
47 set (hax, "view", [-37.5, 30], |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
48 "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
12858
6ceca9beb331
surfc.m: Don't pass color matrix to contour. Bug #33782
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
49 endif |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
50 |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
51 drawnow (); |
12858
6ceca9beb331
surfc.m: Don't pass color matrix to contour. Bug #33782
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
52 |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
53 # don't pass string arguments to __contour__() |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
54 stop_idx = find (cellfun ("isclass", varargin, "char"), 1); |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
55 if (isempty (stop_idx)) |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
56 stop_idx = nargin; |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
57 else |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
58 stop_idx--; |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
59 endif |
12858
6ceca9beb331
surfc.m: Don't pass color matrix to contour. Bug #33782
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
60 |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
61 if (stop_idx - 1 == 1 || stop_idx - 1 == 3) |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
62 ## Don't pass a color matrix c to __contour__ |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
63 stop_idx -= 1; |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
64 endif |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
65 |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
66 zmin = get (hax, "zlim")(1); |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
67 [~, htmp2] = __contour__ (hax, zmin, varargin{1:stop_idx}); |
12858
6ceca9beb331
surfc.m: Don't pass color matrix to contour. Bug #33782
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
68 |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
69 htmp = [htmp; htmp2]; |
7118 | 70 |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
71 unwind_protect_cleanup |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
72 if (! isempty (oldfig)) |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
73 set (0, "currentfigure", oldfig); |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
74 endif |
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
75 end_unwind_protect |
7118 | 76 |
77 if (nargout > 0) | |
17052
1118d566bcd4
surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14247
diff
changeset
|
78 h = htmp; |
7118 | 79 endif |
7146 | 80 |
7118 | 81 endfunction |
12812
4c93cc41da15
codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
82 |
4c93cc41da15
codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
83 |
4c93cc41da15
codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
84 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
85 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
86 %! colormap ('default'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
87 %! [~,~,Z] = peaks (); |
14223
ba7a26030214
Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
88 %! surfc (Z); |
ba7a26030214
Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
89 |
ba7a26030214
Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
90 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
91 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
92 %! colormap ('default'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
93 %! [~,~,Z] = sombrero (); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
94 %! [Fx,Fy] = gradient (Z); |
14223
ba7a26030214
Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
95 %! surfc (Z, Fx+Fy); |
12812
4c93cc41da15
codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
96 %! shading interp; |
4c93cc41da15
codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
97 |
4c93cc41da15
codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
98 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
99 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
100 %! colormap ('default'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
101 %! [X,Y,Z] = sombrero (); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
102 %! [~,Fy] = gradient (Z); |
14223
ba7a26030214
Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
103 %! surfc (X,Y,Z,Fy); |
12812
4c93cc41da15
codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
104 %! shading interp; |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14223
diff
changeset
|
105 |