<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://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:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"  xml:lang="en" xml:id="contour2d">
    <refnamediv>
        <refname>contour2d</refname>
        <refpurpose>level curves of a surface on a 2D
            plot
        </refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            contour2d(x, y, z, nz, [style, strf, leg, rect, nax, fpf])
            contour2d(x, y, z, nz, &lt;opt_args&gt;)
        </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>
                        real matrix of size <literal>(n1,n2)</literal>, the
                        values of the function on the grid or a Scilab function which defines the surface <literal>z=f(x,y)</literal>.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>nz</term>
                <listitem>
                    <para>the level values or the number of levels.</para>
                    <variablelist>
                        <varlistentry>
                            <term>
                                If <literal>nz</literal> is an integer
                            </term>
                            <listitem>
                                <para>
                                    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>
                                If <literal>nz</literal> is a vector
                            </term>
                            <listitem>
                                <para>
                                    <literal>nz(i)</literal> gives the value of
                                    the <literal>i</literal>-th level curve.
                                </para>
                            </listitem>
                        </varlistentry>
                    </variablelist>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>&lt;opt_args&gt;</term>
                <listitem>
                    <para>
                        This represents a sequence of statements
                        <literal>key1=value1, key2=value2</literal>,... where
                        <literal>key1</literal>, <literal>key2</literal>,... can
                        be one of the following: <literal>style</literal>,
                        <literal>leg</literal>, <literal>rect</literal>,
                        <literal>nax</literal>, <literal>strf</literal> or
                        <literal>axesflag</literal> and
                        <literal>frameflag</literal> (see <link linkend="plot2d">plot2d</link>)
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>style, strf, leg, rect, nax</term>
                <listitem>
                    <para>
                        see <link linkend="plot2d">plot2d</link>. The argument
                        <literal>style</literal> gives the dash styles or colors
                        which are to be used for level curves. It must have the
                        same size as the number of levels.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>fpf</term>
                <listitem>
                    <para>
                        You can change the format of the floating point number printed on
                        the levels where <varname>fpf</varname> is the format in C format syntax 
                        (for example <code>fpf="%.3f"</code>).
                        Set <varname>fpf</varname> to " " implies that the level are not drawn on the level curves.
                        If not given, the default format is <literal>"%.3g"</literal>.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            <function>contour2d</function> draws 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>
            The optional arguments <varname>style</varname>,
            <varname>strf</varname>, <varname>leg</varname>,
            <varname>rect</varname>, <varname>nax</varname> can be
            passed by a sequence of statements <literal>key1=value1,
                key2=value2
            </literal>
            ,... where keys may be
            <literal>style</literal>, <literal>strf</literal>,
            <literal>leg</literal>, <literal>rect</literal>,
            <literal>nax</literal>. In this case, the order has no special meaning.
        </para>
        <para>
            Use <function>contour</function> to draw levels curves on a 3D surface.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
contour2d(1:10,1:10,rand(10,10),5,rect=[0,0,11,11])
 ]]></programlisting>
        <scilab:image>
            contour2d(1:10,1:10,rand(10,10),5,rect=[0,0,11,11]);
        </scilab:image>
        <programlisting role="example"><![CDATA[
clf()
// changing the format of the printing of the levels
contour2d(1:10,1:10,rand(10,10),5,rect=[0,0,11,11],fpf="%.2f")
  ]]></programlisting>
        <scilab:image>
            contour2d(1:10,1:10,rand(10,10),5,rect=[0,0,11,11],fpf="%.2f")
        </scilab:image>
        <programlisting role="example"><![CDATA[
// now an example with level numbers drawn in a legend
// Caution there are a number of tricks...
x = linspace(0,4*%pi,80);
z = cos(x')*cos(x);
clf(); f=gcf();
// trick 1: fpf=" " implies that the level numbers are not
//          drawn on the level curves
f.color_map=jet(7);
// trick 2: to be able to put the legend on the right without
//          interfering with the level curves use rect with a xmax
//          value large enough
contour2d(x,x,z,-0.75:0.25:0.75,frameflag=3,rect=[0,0,5*%pi,4*%pi],fpf=" ")
// trick 3: use legends (note that the more practical legend function
//          will not work as soon as one of the level is formed by 2 curves)
legends(string(-0.75:0.25:0.75),1:7,"lr");
xtitle("Some level curves of the function cos(x)cos(y)")
 ]]></programlisting>
        <scilab:image localized="true">
            x = linspace(0,4*%pi,80);
            z = cos(x')*cos(x);

            clf(); f=gcf();

            f.color_map=jet(7);

            contour2d(x,x,z,-0.75:0.25:0.75,frameflag=3,rect=[0,0,5*%pi,4*%pi],fpf=" ")

            legends(string(-0.75:0.25:0.75),1:7,"lr");
            xtitle("Some level curves of the function cos(x)cos(y)")
        </scilab:image>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="contour">contour</link>
            </member>
            <member>
                <link linkend="contour2di">contour2di</link>
            </member>
            <member>
                <link linkend="contour2dm">contour2dm</link>
            </member>
            <member>
                <link linkend="plot2d">plot2d</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
