This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Project 2-D contour plot of map data


C = contourm(___)
[C,h] = contourm(___)


contourm(Z,R) creates a contour plot of the regular data grid Z. R can be a geographic raster reference object, a referencing vector, or a referencing matrix.

contourm(lat,lon,Z) displays a contour plot of the geolocated, M-by-N data grid, Z. lat,lon can be the size of Z or can specify the corresponding row and column dimensions for Z.

contourm(___,n) draws n contour levels.

contourm(___,V) draws contours at the levels specified by the input vector V. Use V = [v v] to compute a single contour at level v.

contourm(___,LineSpec) uses any valid LineSpec to draw the contour lines.

contourm(___,Name,Value,...) allows you to set optional parameters. Parameter names can be abbreviated, and case does not matter. In addition, any of the following hggroup properties may be specified: HandleVisibility, Parent, Tag, UserData, and Visible.

C = contourm(___) returns a standard contour matrix C, with the first row representing longitude data and the second row representing latitude data

[C,h] = contourm(___) returns the contour matrix and the handle to the contour patches drawn onto the current axes. The handle is of type hggroup.

Input Arguments


Regular or geolocated data grid.

If the grid contains regions with missing data, set the corresponding elements of Z to NaN. Contour lines terminate when entering such areas. Similarly, if you use 'Fill','on' or call contourfm, such null-data areas will not be filled. If the syntax contourm(lat,lon,Z, ...) is used, however, lat and lon must have finite, non-NaN values everywhere. In this case, set Z to NaN in null data areas, but make sure the corresponding elements of lat and lon have finite values that specify actual locations on the Earth.


Geographic raster reference object, referencing vector, or referencing matrix.

If R is a geographic raster reference object, its RasterSize property must be consistent with size(Z).

If R is a referencing vector, it must be a 1-by-3 with elements:

[cells/degree northern_latitude_limit western_longitude_limit]

If R is a referencing matrix, it must be 3-by-2 and transform raster row and column indices to/from geographic coordinates according to:

[lon lat] = [row col 1] * R

If R is a referencing matrix, it must define a (non-rotational, non-skewed) relationship in which each column of the data grid falls along a meridian and each row falls along a parallel. For more information about referencing vectors and matrices, see Georeferenced Raster Data. If the current axis is a map axis, the coordinates of Z will be projected using the projection structure from the axis. The contours are drawn at their corresponding Z level.


Geolocation array having the same size as Z, or a vector with length matching the number of rows in Z.


Geolocation array having the same size as Z, or a vector with length matching the number of columns in Z.


Scalar specifying the number of contour levels.


Vector specifying contour levels.


Line specification. See the MATLAB® function reference page for LineSpec for more information.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.


off | on

Color areas between contour lines. By default contourm draws a line (which may have multiple parts) for each contour level. If you set Fill to on, contourm colors the polygonal regions between the lines, selecting a distinct color for each contour interval from the colormap of the figure in which the contours are drawn. Setting Fill to on is almost the same as calling contourfm; the only difference is that contourfm also sets LineColor to black by default.

Default: off



Spacing between labels on each contour line. When you display contour line labels either by calling clabelm or by specifying 'ShowText','on', the labels by default are spaced 144 points (2 inches) apart on each line. You can specify the spacing by setting LabelSpacing to a value in points. If the length of an individual contour line is less than the specified value, only one contour label is displayed on that line.



Values at which contour lines are drawn. This property uses a row vector of increasing values to specify the levels at which contour lines are drawn.



Spacing of contour lines. When LevelStep, which must be a positive real number, is specified, the contourm function draws contour lines at regular intervals determined by the value of LevelStep, unless the optional third argument, n (number of contour levels) or V (vector specifying contour levels) is provided. If n or V is used in combination with the LevelStep parameter, then the LevelStep parameter is ignored. If n, v, and the LevelStep parameter are all omitted, contourm selects a uniform step automatically.


flat | ColorSpec | none

Contour line colors. To specify a single color to be used for all the contour lines, you can set ColorSpec to a three-element RGB vector or one of the MATLAB predefined names. See the MATLAB ColorSpec reference page for more information on specifying color. If you omit LineColor or set it to flat, contourm selects a distinct color for lines at each contour level from the colormap of the figure in which the contours are drawn. If you set LineColor to none, the contour lines will not be visible.

Default: flat


- | -- | : | -. | none

Line style for contour lines. Options for LineStyle include solid (-), dashed (--), dotted (:), dash-dot (-.), and 'none'. The specifiers work the same as for line objects in MATLAB graphics.

Default: -



Width of the contour lines in points (1 point = 1/72 inch).

Default: 0.5


on | off

Display labels on contour lines. If you set ShowText to on, contourm displays text labels on each contour line indicating the value of the corresponding contour level. Another way to add labels to your contour lines is to call clabelm after calling contourm.

Default: off

Output Arguments


Standard contour matrix with the first row representing longitude data and the second row representing latitude data.


Handle to the hggroup containing the contour lines.


collapse all

Load EGM96 geoid heights.

load geoid

Display contours.

[c,h] = contourm(geoid,geoidrefvec,'LevelStep',20,'ShowText','on');

Add axes labels and a legend.


Contour geoid heights for an area including Korea with a backdrop of terrain elevations and bathymetry.

Load geoid heights and Korea data.

load korea5c
load geoid60c

Create a map axes that includes Korea.


Display the digital elevation data and apply a colormap.


Display contours of the geoid values from -100 to 100 in increments of 5.

[c,h] = contourm(geoid60c,geoid60cR,-100:5:100,'k');

Add red labels with white backgrounds to the contours.

t = clabelm(c,h);


You have three ways to control the number of contour levels that display in your map:

  1. Set the number of contour levels by specifying the scalar n in the syntax contourm(Z,R,n) or contourm(lat,lon,Z,n).

  2. Use the vector V to specify the levels at which contours are drawn with the syntax contourm(Z,R,V) or contourm(lat,lon,Z,V).

  3. Choose regular intervals at which the contours are drawn by setting the LevelStep parameter.

If you do not use any of the above methods to set your contour levels, the contourm function will display around five contour levels.

Introduced before R2006a

Was this topic helpful?