<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) ENPC - Jean-Philippe Chancelier
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"  xml:id="contourf" xml:lang="en">
    <refnamediv>
        <refname>contourf</refname>
        <refpurpose>filled level curves of a surface on a 2D plot</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            contourf(x, y, z, nz, [style, strf, leg, rect, nax])
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>x, y</term>
                <listitem>
                    <para>
                        two real row vectors of size <literal>n1</literal> and <literal>n2</literal>: the grid.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>z</term>
                <listitem>
                    <para>
                        a real matrix of size <literal>(n1,n2)</literal>, the
                        values of the function.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>nz</term>
                <listitem>
                    <para>the level values or the number of levels.</para>
                    <variablelist>
                        <varlistentry>
                            <term>-</term>
                            <listitem>
                                <para>
                                    If <varname>nz</varname> is an integer, its
                                    value gives the number of level curves
                                    equally spaced from <literal>zmin</literal>
                                    to <literal>zmax</literal> as follows:
                                </para>
                                <programlisting role="no-scilab-exec"><![CDATA[
z= zmin + (1:nz)*(zmax-zmin)/(nz+1)
 ]]></programlisting>
                                <para>
                                    <note>
                                        Note: that the <literal>zmin</literal> and
                                        <literal>zmax</literal> levels are not drawn
                                        (generically they are reduced to points) but
                                        they can be added with
                                    </note>
                                </para>
                                <programlisting role="no-scilab-exec"><![CDATA[
[im,jm] = find(z == zmin);     // or zmax
plot2d(x(im)',y(jm)',-9,"000")
 ]]></programlisting>
                            </listitem>
                        </varlistentry>
                        <varlistentry>
                            <term>-</term>
                            <listitem>
                                <para>
                                    If <varname>nz</varname> is a vector,
                                    <literal>nz(i)</literal> gives the value of
                                    the <literal>i</literal>-th level curve.
                                </para>
                            </listitem>
                        </varlistentry>
                    </variablelist>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>style, strf, leg, rect, nax</term>
                <listitem>
                    <para>
                        see <function>plot2d</function>. The argument
                        <varname>style</varname> gives the colors which are to
                        be used for level curves. It must have the same size as
                        the number of levels.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            <function>contourf</function> paints surface between two consecutive
            level curves of a surface <literal>z=f(x,y)</literal> on a 2D plot.
            The values of <literal>f(x,y)</literal> are given by the matrix
            <varname>z</varname> at the grid points defined by
            <varname>x</varname> and <varname>y</varname>.
        </para>
        <para>
            You can change the format of the floating point number printed on
            the levels by using <code>xset("fpf",string)</code> where
            <varname>string</varname> gives the format in C format syntax (for
            example <code>string="%.3f"</code>). Use <code>string=""</code> to
            switch back to default format.
        </para>
        <para>
            Enter the command <code>contourf()</code> to see a demo.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
contourf(1:10,1:10,rand(10,10),5,1:5,"011"," ",[0,0,11,11])
 ]]></programlisting>
        <scilab:image>
            contourf(1:10,1:10,rand(10,10),5,1:5,"011"," ",[0,0,11,11])
        </scilab:image>
        <programlisting role="example"><![CDATA[
function z=peaks(x,y)
x1=x(:).*.ones(1,size(y,'*'));
y1=y(:)'.*.ones(size(x,'*'),1);
z =  (3*(1-x1).^2).*exp(-(x1.^2) - (y1+1).^2) ...
   - 10*(x1/5 - x1.^3 - y1.^5).*exp(-x1.^2-y1.^2) ...
   - 1/3*exp(-(x1+1).^2 - y1.^2)
endfunction

function z=peakit()
x=-4:0.1:4;y=x;z=peaks(x,y);
endfunction

z=peakit();

levels=[-6:-1,-logspace(-5,0,10),logspace(-5,0,10),1:8];
m=size(levels,'*');
n = fix(3/8*m);
r = [(1:n)'/n; ones(m-n,1)];
g = [zeros(n,1); (1:n)'/n; ones(m-2*n,1)];
b = [zeros(2*n,1); (1:m-2*n)'/(m-2*n)];
h = [r g b];
gcf().color_map = h;
xset('fpf',' ');
clf();
contourf([],[],z,[-6:-1,-logspace(-5,0,10),logspace(-5,0,10),1:8],0*ones(1,m))

xset('fpf','');
clf();
contourf([],[],z,[-6:-1,-logspace(-5,0,10),logspace(-5,0,10),1:8]);
 ]]></programlisting>
        <scilab:image>
            function z=peaks(x,y)
            x1=x(:).*.ones(1,size(y,'*'));
            y1=y(:)'.*.ones(size(x,'*'),1);
            z =  (3*(1-x1).^2).*exp(-(x1.^2) - (y1+1).^2) ...
            - 10*(x1/5 - x1.^3 - y1.^5).*exp(-x1.^2-y1.^2) ...
            - 1/3*exp(-(x1+1).^2 - y1.^2)
            endfunction

            function z=peakit()
            x=-4:0.1:4;y=x;z=peaks(x,y);
            endfunction

            z=peakit();

            levels=[-6:-1,-logspace(-5,0,10),logspace(-5,0,10),1:8];
            m=size(levels,'*');
            n = fix(3/8*m);
            r = [(1:n)'/n; ones(m-n,1)];
            g = [zeros(n,1); (1:n)'/n; ones(m-2*n,1)];
            b = [zeros(2*n,1); (1:m-2*n)'/(m-2*n)];
            h = [r g b];
            gcf().color_map = h;
            xset('fpf',' ');
            clf();
            contourf([],[],z,[-6:-1,-logspace(-5,0,10),logspace(-5,0,10),1:8],0*ones(1,m))
        </scilab:image>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="contour">contour</link>
            </member>
            <member>
                <link linkend="contour2d">contour2d</link>
            </member>
            <member>
                <link linkend="contour2di">contour2di</link>
            </member>
            <member>
                <link linkend="plot2d">plot2d</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
