contourm

Project 2-D contour plot of map data

Syntax

contourm(Z,R)
contourm(lat,lon,Z)
contourm(___,n)
contourm(___,V)
contourm(___,LineSpec)
contourm(___,Name,Value,...)
C = contourm(___)
[C,h] = contourm(___)

Description

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 string 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

Z

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.

R

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 Understanding Raster Geodata. 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.

lat

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

lon

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

n

Scalar specifying the number of contour levels.

V

Vector specifying contour levels.

LineSpec

Line specification string. 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.

'Fill'

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

'LabelSpacing'

scalar

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.

'LevelList'

vector

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.

'LevelStep'

scalar

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.

'LineColor'

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

'LineStyle'

- | -- | : | -. | none

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

Default: -

'LineWidth'

scalar

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

Default: 0.5

'ShowText'

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

C

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

h

Handle to the hggroup containing the contour lines.

Examples

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

% Load the data.
load korea
load geoid

% Create a map axes that includes Korea.
figure
worldmap(map, refvec)

% Display the digital elevation data and apply a colormap.
geoshow(map, refvec, 'DisplayType', 'texturemap');
demcmap(map)

% Contour the geoid values from -100 to 100 in increments of 5.
[c,h] = contourm(geoid, geoidlegend, -100:5:100, 'k');

% Add red labels with white backgrounds to the contours.
ht = clabelm(c,h);
set(ht,'Color','r','BackgroundColor','white','FontWeight','bold')

Display Contours for EGM96 Geoid Heights

Load EGM96 geoid heights.

load geoid

Display contours.

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

Add axes labels and a legend.

xlabel('Longitude')
ylabel('Latitude')
clegendm(c,h,-1)

Display Contour Geoid Heights for Area Including Korea

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

Load geoid heights and Korea data.

load korea
load geoid

Create a map axes that includes Korea.

figure
worldmap(map, refvec)

Display the digital elevation data and apply a colormap.

geoshow(map, refvec, 'DisplayType', 'texturemap');
demcmap(map)

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

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

Add red labels with white backgrounds to the contours.

ht = clabelm(c,h);
[ht.Color] = deal('r');
[ht.BackgroundColor] = deal('white');
[ht.FontWeight] = deal('bold');

More About

expand all

Tips

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.

Was this topic helpful?