]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/contour.m
update packages
[CreaPhase.git] / octave_packages / m / plot / contour.m
1 ## Copyright (C) 1993-2012 Shai Ayal
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} {} contour (@var{z})
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{})
26 ## @deftypefnx {Function File} {[@var{c}, @var{h}] =} contour (@dots{})
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
29 ## arguments; see the latter for their interpretation.  The set of
30 ## contour levels, @var{c}, is only returned if requested.  For example:
31 ##
32 ## @example
33 ## @group
34 ## x = 0:2;
35 ## y = x;
36 ## z = x' * y;
37 ## contour (x, y, z, 2:3)
38 ## @end group
39 ## @end example
40 ##
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 ##
45 ## The optional input and output argument @var{h} allows an axis handle to
46 ## be passed to @code{contour} and the handles to the contour objects to be
47 ## returned.
48 ## @seealso{contourc, patch, plot}
49 ## @end deftypefn
50
51 ## Author: Shai Ayal <shaiay@users.sourceforge.net>
52
53 function [c, h] = contour (varargin)
54
55   [xh, varargin] = __plt_get_axis_arg__ ("contour", varargin{:});
56
57   oldh = gca ();
58   unwind_protect
59     axes (xh);
60     newplot ();
61     [ctmp, htmp] = __contour__ (xh, "none", varargin{:});
62   unwind_protect_cleanup
63     axes (oldh);
64   end_unwind_protect
65
66   if (nargout > 0)
67     c = ctmp;
68     h = htmp;
69   endif
70
71 endfunction
72
73 %!demo
74 %! clf ()
75 %! [x, y, z] = peaks ();
76 %! contour (x, y, z);
77
78 %!demo
79 %! clf ()
80 %! [theta, r] = meshgrid (linspace (0, 2*pi, 64), linspace(0,1,64));
81 %! [X, Y] = pol2cart (theta, r);
82 %! Z = sin(2*theta).*(1-r);
83 %! contour(X, Y, abs(Z), 10)
84
85 %!demo
86 %! clf ()
87 %! x = linspace (-2, 2);
88 %! [x, y] = meshgrid (x);
89 %! z = sqrt (x.^2 + y.^2) ./ (x.^2 + y.^2+1);
90 %! contourf (x, y, z, [0.4, 0.4])
91 %! title ("The hole should be filled with the background color")
92