Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - Français

Change language to:
English - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.1.0. This page might be outdated.
See the recommended documentation of this function

Aide de Scilab >> Graphiques > 2d_plot > contour2d


level curves of a surface on a 2D plot


contour2d(x, y, z, nz, [style, strf, leg, rect, nax])
contour2d(x, y, z, nz, <opt_args>)


x, y

two real row vectors of size n1 and n2: the grid.


real matrix of size (n1,n2), the values of the function on the grid or a Scilab function which defines the surface z=f(x,y).


the level values or the number of levels.

If nz is an integer

its value gives the number of level curves equally spaced from zmin to zmax as follows:

z= zmin + (1:nz)*(zmax-zmin)/(nz+1)

Note that the zmin and zmax levels are not drawn (generically they are reduced to points) but they can be added with

[im,jm] = find(z == zmin); // or zmax
If nz is a vector

nz(i) gives the value of the i-th level curve.


This represents a sequence of statements key1=value1, key2=value2,... where key1, key2,... can be one of the following: style, leg, rect, nax, strf or axesflag and frameflag (see plot2d)

style, strf, leg, rect, nax

see plot2d. The argument style 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.


contour2d draws level curves of a surface z=f(x,y) on a 2D plot. The values of f(x,y) are given by the matrix z at the grid points defined by x and y.

You can change the format of the floating point number printed on the levels by using xset("fpf",string) where string gives the format in C format syntax (for example string="%.3f"). Use string="" to switch back to default format and use string=" " to suppress printing. This last feature is useful in conjunction with legends to display the level numbers in a legend and not directly onto the level curves as usual (see Examples).

The optional arguments style, strf, leg, rect, nax can be passed by a sequence of statements key1=value1, key2=value2 ,... where keys may be style, strf, leg, rect, nax. In this case, the order has no special meaning.

Use contour to draw levels curves on a 3D surface.


// changing the format of the printing of the levels
// 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();
xset("fpf"," ")
// trick 1: this implies that the level numbers are not
//          drawn on the level curves
// 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
// 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)
xtitle("Some level curves of the function cos(x)cos(y)")

See also

  • contour — level curves on a 3D surface
  • contour2di — calcule les courbes de niveau d'une surface
  • contour2dm — compute level curves of a surface defined with a mesh
  • plot2d — 2D plot
Report an issue
<< comet 2d_plot contour2di >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:50:26 CET 2020