Mercurial > octave-nkf
annotate scripts/plot/draw/contour.m @ 20595:c1a6c31ac29a
eliminate more simple uses of error_state
* ov-classdef.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Oct 2015 00:20:02 -0400 |
parents | 777f26aa8e3e |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19627
diff
changeset
|
1 ## Copyright (C) 1993-2015 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}) | |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
25 ## @deftypefnx {Function File} {} contour (@var{hax}, @dots{}) |
7170 | 26 ## @deftypefnx {Function File} {[@var{c}, @var{h}] =} contour (@dots{}) |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
27 ## Create a 2-D contour plot. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
28 ## |
6604 | 29 ## Plot level curves (contour lines) of the matrix @var{z}, using the |
30 ## contour matrix @var{c} computed by @code{contourc} from the same | |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
31 ## arguments; see the latter for their interpretation. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
32 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
33 ## The appearance of contour lines can be defined with a line style @var{style} |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
34 ## in the same manner as @code{plot}. Only line style and color are used; |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
35 ## Any markers defined by @var{style} are ignored. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
36 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
37 ## If the first argument @var{hax} is an axes handle, then plot into this axis, |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
38 ## rather than the current axes returned by @code{gca}. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
39 ## |
20208
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
40 ## The optional output @var{c} contains the contour levels in @code{contourc} |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
41 ## format. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
42 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
43 ## The optional return value @var{h} is a graphics handle to the hggroup |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
44 ## comprising the contour lines. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
45 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
46 ## Example: |
6257 | 47 ## |
48 ## @example | |
6604 | 49 ## @group |
50 ## x = 0:2; | |
51 ## y = x; | |
52 ## z = x' * y; | |
53 ## contour (x, y, z, 2:3) | |
54 ## @end group | |
6257 | 55 ## @end example |
7170 | 56 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17050
diff
changeset
|
57 ## @seealso{ezcontour, contourc, contourf, contour3, clabel, meshc, surfc, caxis, colormap, plot} |
7317 | 58 ## |
3368 | 59 ## @end deftypefn |
4 | 60 |
7327 | 61 ## Author: Shai Ayal <shaiay@users.sourceforge.net> |
6257 | 62 |
7170 | 63 function [c, h] = contour (varargin) |
6434 | 64 |
17050
9ff7d4849f03
contour[3f].m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16911
diff
changeset
|
65 [hax, varargin] = __plt_get_axis_arg__ ("contour", varargin{:}); |
7216 | 66 |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
67 oldfig = []; |
17301
68bcac3c043a
Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents:
17257
diff
changeset
|
68 if (! isempty (hax)) |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
69 oldfig = get (0, "currentfigure"); |
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
70 endif |
7215 | 71 unwind_protect |
17050
9ff7d4849f03
contour[3f].m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16911
diff
changeset
|
72 hax = newplot (hax); |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
73 |
17050
9ff7d4849f03
contour[3f].m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16911
diff
changeset
|
74 [ctmp, htmp] = __contour__ (hax, "none", varargin{:}); |
7215 | 75 unwind_protect_cleanup |
17050
9ff7d4849f03
contour[3f].m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16911
diff
changeset
|
76 if (! isempty (oldfig)) |
9ff7d4849f03
contour[3f].m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16911
diff
changeset
|
77 set (0, "currentfigure", oldfig); |
9ff7d4849f03
contour[3f].m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16911
diff
changeset
|
78 endif |
7215 | 79 end_unwind_protect |
6257 | 80 |
81 if (nargout > 0) | |
7170 | 82 c = ctmp; |
7189 | 83 h = htmp; |
4 | 84 endif |
85 | |
86 endfunction | |
7245 | 87 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
88 |
7245 | 89 %!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
|
90 %! 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
|
91 %! colormap ('default'); |
7245 | 92 %! [x, y, z] = peaks (); |
93 %! contour (x, y, z); | |
17257
ce55a8575874
Fix typo in titles for contour/contourf demos.
Rik <rik@octave.org>
parents:
17211
diff
changeset
|
94 %! title ({'contour() plot (isolines of constant Z)'; 'Z = peaks()'}); |
7327 | 95 |
96 %!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
|
97 %! 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
|
98 %! 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
|
99 %! [theta, r] = meshgrid (linspace (0,2*pi,64), linspace (0,1,64)); |
7331 | 100 %! [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
|
101 %! 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
|
102 %! contour (X, Y, abs (Z), 10); |
17257
ce55a8575874
Fix typo in titles for contour/contourf demos.
Rik <rik@octave.org>
parents:
17211
diff
changeset
|
103 %! title ({'contour() plot'; 'polar fcn: Z = sin (2*theta) * (1-r)'}); |
13156
da71f676e449
Fix bug #34282. Fill holes in contours with the background colour
Ben Abbott <bpabbott@mac.com>
parents:
11587
diff
changeset
|
104 |
17525
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
105 %!demo |
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
106 %! clf; |
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
107 %! colormap ('default'); |
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
108 %! z = peaks (); |
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
109 %! contour (z, [0 0]); |
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
110 %! title ({'contour() plot with single isoline at Z == 0'; 'Z = peaks()'}); |
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
111 |
16911 | 112 %!test |
113 %! hf = figure ("visible", "off"); | |
114 %! clf (hf); | |
115 %! unwind_protect | |
116 %! [x, y, z] = peaks (); | |
117 %! [c, h] = contour (x, y, z); | |
17525
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
118 %! levellist = -6:6; |
16911 | 119 %! set (h, "levellist", levellist); |
120 %! assert (get (h, "levellist"), levellist) | |
121 %! assert (get (h, "levellistmode"), "manual") | |
122 %! unwind_protect_cleanup | |
123 %! close (hf); | |
124 %! end_unwind_protect | |
125 | |
126 %!test | |
127 %! hf = figure ("visible", "off"); | |
128 %! clf (hf); | |
129 %! unwind_protect | |
130 %! [x, y, z] = peaks (); | |
131 %! [c, h] = contour (x, y, z); | |
132 %! levelstep = 3; | |
133 %! set (h, "levelstep", levelstep); | |
134 %! assert (get (h, "levelstep"), levelstep) | |
135 %! assert (get (h, "levelstepmode"), "manual") | |
17525
76a6d7de4cbc
Fix multiple problem with listeners for contour groups.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
136 %! assert (get (h, "levellist"), -6:levelstep:6) |
16911 | 137 %! assert (get (h, "levellistmode"), "auto") |
138 %! unwind_protect_cleanup | |
139 %! close (hf); | |
140 %! end_unwind_protect | |
141 |