Mercurial > hg > octave-lyh
annotate scripts/plot/contour.m @ 16950:b34202b24212
fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
* scripts/plot/fplot.m: Add ability to specify n,tol,fmt in any order and
simultaneously. Return data rather than plotting it if asked. Use
additional test on progress of algorithm to decide whether to quit. Add
%!demo and %!tests.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 11 Jul 2013 09:25:54 -0700 |
parents | 5ea6a6d2b83f |
children | 9ff7d4849f03 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13156
diff
changeset
|
1 ## Copyright (C) 1993-2012 Shai Ayal |
2313 | 2 ## |
6440 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
2313 | 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. | |
2313 | 9 ## |
6440 | 10 ## Octave is distributed in the hope that it will be useful, but |
2313 | 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/>. | |
245 | 18 |
3368 | 19 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
20 ## @deftypefn {Function File} {} contour (@var{z}) |
7317 | 21 ## @deftypefnx {Function File} {} contour (@var{z}, @var{vn}) |
22 ## @deftypefnx {Function File} {} contour (@var{x}, @var{y}, @var{z}) | |
23 ## @deftypefnx {Function File} {} contour (@var{x}, @var{y}, @var{z}, @var{vn}) | |
24 ## @deftypefnx {Function File} {} contour (@dots{}, @var{style}) | |
25 ## @deftypefnx {Function File} {} contour (@var{h}, @dots{}) | |
7170 | 26 ## @deftypefnx {Function File} {[@var{c}, @var{h}] =} contour (@dots{}) |
6604 | 27 ## Plot level curves (contour lines) of the matrix @var{z}, using the |
28 ## contour matrix @var{c} computed by @code{contourc} from the same | |
6895 | 29 ## arguments; see the latter for their interpretation. The set of |
30 ## contour levels, @var{c}, is only returned if requested. For example: | |
6257 | 31 ## |
32 ## @example | |
6604 | 33 ## @group |
34 ## x = 0:2; | |
35 ## y = x; | |
36 ## z = x' * y; | |
37 ## contour (x, y, z, 2:3) | |
38 ## @end group | |
6257 | 39 ## @end example |
7170 | 40 ## |
7317 | 41 ## The style to use for the plot can be defined with a line style @var{style} |
42 ## in a similar manner to the line styles used with the @code{plot} command. | |
43 ## Any markers defined by @var{style} are ignored. | |
44 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
45 ## The optional input and output argument @var{h} allows an axis handle to |
7170 | 46 ## be passed to @code{contour} and the handles to the contour objects to be |
47 ## returned. | |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
48 ## @seealso{contourc, contourf, contour3, patch, plot} |
3368 | 49 ## @end deftypefn |
4 | 50 |
7327 | 51 ## Author: Shai Ayal <shaiay@users.sourceforge.net> |
6257 | 52 |
7170 | 53 function [c, h] = contour (varargin) |
6434 | 54 |
7216 | 55 [xh, varargin] = __plt_get_axis_arg__ ("contour", varargin{:}); |
56 | |
7215 | 57 oldh = gca (); |
58 unwind_protect | |
7216 | 59 axes (xh); |
7170 | 60 newplot (); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
7331
diff
changeset
|
61 [ctmp, htmp] = __contour__ (xh, "none", varargin{:}); |
7215 | 62 unwind_protect_cleanup |
63 axes (oldh); | |
64 end_unwind_protect | |
6257 | 65 |
66 if (nargout > 0) | |
7170 | 67 c = ctmp; |
7189 | 68 h = htmp; |
4 | 69 endif |
70 | |
71 endfunction | |
7245 | 72 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
73 |
7245 | 74 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
75 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14245
diff
changeset
|
76 %! colormap ('default'); |
7245 | 77 %! [x, y, z] = peaks (); |
78 %! contour (x, y, z); | |
7327 | 79 |
80 %!demo | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
81 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14245
diff
changeset
|
82 %! colormap ('default'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 %! [theta, r] = meshgrid (linspace (0,2*pi,64), linspace (0,1,64)); |
7331 | 84 %! [X, Y] = pol2cart (theta, r); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
85 %! Z = sin (2*theta) .* (1-r); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
86 %! contour (X, Y, abs (Z), 10); |
13156
da71f676e449
Fix bug #34282. Fill holes in contours with the background colour
Ben Abbott <bpabbott@mac.com>
parents:
11587
diff
changeset
|
87 |
da71f676e449
Fix bug #34282. Fill holes in contours with the background colour
Ben Abbott <bpabbott@mac.com>
parents:
11587
diff
changeset
|
88 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
89 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14245
diff
changeset
|
90 %! colormap ('default'); |
13156
da71f676e449
Fix bug #34282. Fill holes in contours with the background colour
Ben Abbott <bpabbott@mac.com>
parents:
11587
diff
changeset
|
91 %! x = linspace (-2, 2); |
da71f676e449
Fix bug #34282. Fill holes in contours with the background colour
Ben Abbott <bpabbott@mac.com>
parents:
11587
diff
changeset
|
92 %! [x, y] = meshgrid (x); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
93 %! z = sqrt (x.^2 + y.^2) ./ (x.^2 + y.^2 + 1); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
94 %! contourf (x, y, z, [0.4, 0.4]); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
95 %! title ('The hole should be filled with the background color'); |
13156
da71f676e449
Fix bug #34282. Fill holes in contours with the background colour
Ben Abbott <bpabbott@mac.com>
parents:
11587
diff
changeset
|
96 |
16911 | 97 %!test |
98 %! hf = figure ("visible", "off"); | |
99 %! clf (hf); | |
100 %! unwind_protect | |
101 %! [x, y, z] = peaks (); | |
102 %! [c, h] = contour (x, y, z); | |
103 %! levellist = (-6):6; | |
104 %! set (h, "levellist", levellist); | |
105 %! assert (get (h, "levellist"), levellist) | |
106 %! assert (get (h, "levellistmode"), "manual") | |
107 %! unwind_protect_cleanup | |
108 %! close (hf); | |
109 %! end_unwind_protect | |
110 | |
111 %!test | |
112 %! hf = figure ("visible", "off"); | |
113 %! clf (hf); | |
114 %! unwind_protect | |
115 %! [x, y, z] = peaks (); | |
116 %! [c, h] = contour (x, y, z); | |
117 %! levelstep = 3; | |
118 %! set (h, "levelstep", levelstep); | |
119 %! assert (get (h, "levelstep"), levelstep) | |
120 %! assert (get (h, "levelstepmode"), "manual") | |
121 %! assert (get (h, "levellist"), (-6):levelstep:6) | |
122 %! assert (get (h, "levellistmode"), "auto") | |
123 %! unwind_protect_cleanup | |
124 %! close (hf); | |
125 %! end_unwind_protect | |
126 |