Main Content


Add legend labels to map contour display


clegendm(C,h) adds a legend specifying the contour line heights, C, to the current map contour plot, h.

clegendm(C,h,loc) places the legend in a specified location.


clegendm(___,unitstr) appends a string unitstr to each entry in the legend.

clegendm(___,labels) uses the text specified in labels to label the legend.

hl = clegendm(___) returns the handle to the legend object created.


collapse all

Load elevation raster data and a geographic cells reference object. Display the data using a contour plot on a world map. Then, create a legend in the lower-right corner of the map. Specify the contour elevations as meters.

load topo60c
[c,h] = contourm(topo60c,topo60cR,-6000:1500:6000);

Input Arguments

collapse all

Contour matrix, specified as a matrix with two rows. The first row represents longitude data and the second row represents latitude data. You can create a contour matrix by using contourm, contour3m, or contourfm.

Handle to the contour patches displayed on the current axes, returned as an hggroup. You can get a handle to contour patches by using contourm, contour3m, or contourfm.

Location to place legend, specified as one of the following integers.


Automatic placement (default)


Upper right corner


Upper left corner


Lower left corner


Lower right corner


To the right of the plot

Text to append to each entry in the legend, specified as a character vector or string scalar.

Labels in the legend, specified as a string array or cell array of character vectors. labels must have the same number of entries as the line children of h.

Output Arguments

collapse all

Handle to legend object created by the clegendm function, returned as a handle.

Version History

Introduced before R2006a