contourm

Project 2-D contour plot of map data

Description

example

contourm(Z,R) creates a contour plot of the regular data grid Z with geographic reference R.

contourm(lat,lon,Z) displays a contour plot of the geolocated data grid, Z with geolocation defined by lat and lon.

contourm(___,n) draws n contour levels.

example

contourm(___,V) draws contours at the levels specified by 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 can 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.

Examples

collapse all

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)

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.

figure
worldmap(korea5c,korea5cR)

Display the digital elevation data and apply a colormap.

geoshow(korea5c,korea5cR,'DisplayType','texturemap')
demcmap(korea5c)

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);
set(t,'Color','r')
set(t,'BackgroundColor','white')
set(t,'FontWeight','bold')

Input Arguments

collapse all

Regular or geolocated data grid, specified as an M-by-N matrix.

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 you use the syntax contourm(lat,lon,Z,...), 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 reference, specified as one of the following. For more information about referencing vectors and matrices, see Georeferenced Raster Data.

TypeDescription
Geographic raster reference object

GeographicCellsReference or GeographicPostingsReference geographic raster reference object. The RasterSize property must be consistent with the size of the data grid, size(Z).

Vector

1-by-3 numeric vector with elements:

[cells/degree northern_latitude_limit western_longitude_limit]
Matrix

3-by-2 numeric matrix that transforms raster row and column indices to or from geographic coordinates according to:

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

R defines 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 are projected using the projection structure from the axis. The contours are drawn at their corresponding Z level.

Geolocation array with latitude or longitude coordinates, specified as a matrix of the same size as Z, or a vector with length matching the number of rows in Z.

Number of contour levels, specified as a numeric scalar.

Value of contour levels, specified as a numeric vector with length greater than or equal to two. Use V = [v v] to compute a single contour at level v.

Line specification, specified as a LineSpec.

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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'LabelSpacing',72

Color areas between contour lines, specified as the comma-separated pair consisting of 'Fill' and 'off' or 'on'. By default contourm draws a line (which may have multiple parts) for each contour level. If you set Fill to 'on', then 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.

Spacing between labels on each contour line, specified as the comma-separated pair consisting of 'LabelSpacing' and a numeric scalar. 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, specified as the comma-separated pair consisting of 'LevelList' and a numeric vector. This property uses a row vector of increasing values to specify the levels at which contour lines are drawn.

Spacing of contour lines, specified as the comma-separated pair consisting of 'LevelStep' and a numeric scalar. 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.

Contour line colors, specified as the comma-separated pair consisting of 'LineColor' and 'flat', a ColorSpec, or 'none'. To specify a single color to be used for all the contour lines, you can specify a ColorSpec consisting of a three-element RGB vector or one of the MATLAB® predefined names. 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.

Line style for contour lines, specified as the comma-separated pair consisting of 'LineStyle' and '-' (solid), '--' (dashed), ':' (dotted), '-.' (dash-dot), or 'none'. The specifiers work the same as for line objects in MATLAB graphics.

Width of contour lines in points, specified as the comma-separated pair consisting of 'LineWidth' and a numeric scalar. 1 point = 1/72 inch.

Flag to display labels on contour lines, specified as the comma-separated pair consisting of 'ShowText' and 'off' or 'on'. 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.

Output Arguments

collapse all

Standard contour matrix, returned as a matrix with two rows. The first row represents longitude data and the second row represents latitude data.

Handle to the contour patches drawn onto the current axes, returned as an hggroup.

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 displays around five contour levels.

Introduced before R2006a