1########################################################################
2##
3## Copyright (C) 2003-2021 The Octave Project Developers
4##
5## See the file COPYRIGHT.md in the top-level directory of this
6## distribution or <https://octave.org/copyright/>.
7##
8## This file is part of Octave.
9##
10## Octave is free software: you can redistribute it and/or modify it
11## under the terms of the GNU General Public License as published by
12## the Free Software Foundation, either version 3 of the License, or
13## (at your option) any later version.
14##
15## Octave is distributed in the hope that it will be useful, but
16## WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18## GNU General Public License for more details.
19##
20## You should have received a copy of the GNU General Public License
21## along with Octave; see the file COPYING.  If not, see
22## <https://www.gnu.org/licenses/>.
23##
24########################################################################
25
26## -*- texinfo -*-
27## @deftypefn  {} {} contourf (@var{z})
28## @deftypefnx {} {} contourf (@var{z}, @var{vn})
29## @deftypefnx {} {} contourf (@var{x}, @var{y}, @var{z})
30## @deftypefnx {} {} contourf (@var{x}, @var{y}, @var{z}, @var{vn})
31## @deftypefnx {} {} contourf (@dots{}, @var{style})
32## @deftypefnx {} {} contourf (@var{hax}, @dots{})
33## @deftypefnx {} {[@var{c}, @var{h}] =} contourf (@dots{})
34## Create a 2-D contour plot with filled intervals.
35##
36## Plot level curves (contour lines) of the matrix @var{z} and fill the region
37## between lines with colors from the current colormap.
38##
39## The level curves are taken from the contour matrix @var{c} computed by
40## @code{contourc} for the same arguments; see the latter for their
41## interpretation.
42##
43## The appearance of contour lines can be defined with a line style @var{style}
44## in the same manner as @code{plot}.  Only line style and color are used;
45## Any markers defined by @var{style} are ignored.
46##
47## If the first argument @var{hax} is an axes handle, then plot into this axes,
48## rather than the current axes returned by @code{gca}.
49##
50## The optional output @var{c} contains the contour levels in @code{contourc}
51## format.
52##
53## The optional return value @var{h} is a graphics handle to the hggroup
54## comprising the contour lines.
55##
56## The following example plots filled contours of the @code{peaks} function.
57##
58## @example
59## @group
60## [x, y, z] = peaks (50);
61## contourf (x, y, z, -7:9)
62## @end group
63## @end example
64## @seealso{ezcontourf, contour, contourc, contour3, clabel, meshc, surfc, caxis, colormap, plot}
65## @end deftypefn
66
67function [c, h] = contourf (varargin)
68
69  [hax, varargin] = __plt_get_axis_arg__ ("contour", varargin{:});
70
71  oldfig = [];
72  if (! isempty (hax))
73    oldfig = get (0, "currentfigure");
74  endif
75  unwind_protect
76    hax = newplot (hax);
77
78    [ctmp, htmp] = __contour__ (hax, "none", "fill", "on",
79                                     "linecolor", "black", varargin{:});
80
81    if (! ishold ())
82      set (hax, "box", "on");
83    endif
84
85  unwind_protect_cleanup
86    if (! isempty (oldfig))
87      set (0, "currentfigure", oldfig);
88    endif
89  end_unwind_protect
90
91  if (nargout > 0)
92    c = ctmp;
93    h = htmp;
94  endif
95
96endfunction
97
98
99%!demo
100%! clf;
101%! colormap ("default");
102%! [x, y, z] = peaks (50);
103%! contourf (x, y, z, -7:9);
104%! title ({"contourf() plot (filled contour lines)"; "Z = peaks()"});
105
106%!demo
107%! clf;
108%! colormap ("default");
109%! [theta, r] = meshgrid (linspace (0,2*pi,64), linspace (0,1,64));
110%! [X, Y] = pol2cart (theta, r);
111%! Z = sin (2*theta) .* (1-r);
112%! contourf (X, Y, abs (Z), 10);
113%! title ({"contourf() plot"; "polar fcn: Z = sin (2*theta) * (1-r)"});
114
115%!demo
116%! clf;
117%! colormap ("default");
118%! x = linspace (-2, 2);
119%! [x, y] = meshgrid (x);
120%! z = sqrt (x.^2 + y.^2) ./ (x.^2 + y.^2 + 1);
121%! contourf (x, y, z, [0.4, 0.4]);
122%! title ("Hole should be filled with the background color");
123