Documentation Center

  • Trial Software
  • Product Updates

clabel

Contour plot elevation labels

Syntax

  • clabel(C,'manual')
  • clabel(C,h,'manual')

Description

example

clabel(C) labels all contours displayed in the current contour plot. Labels are upright and displayed with '+' symbols. clabel randomly selects label positions.

example

clabel(C,h) rotates the labels and inserts them in the contour lines. This syntax inserts only those labels that fit within the contour, depending on the size of the contour.

clabel(C,v) labels only the contour levels specified by the vector, v.

example

clabel(C,h,v) labels only the contour levels specified by vector v, rotates the labels, and inserts them in the contour lines.

example

clabel(___,Name,Value) specifies the text object properties and the 'LabelSpacing' contourgroup property, using one or more Name,Value pair arguments, in addition to any of the input arguments in previous syntaxes.

clabel(C,'manual') places contour labels at locations you select with a mouse. Click the mouse or press the space bar to label the contour closest to the center of the crosshair. Press the Return key while the cursor is within the figure window to terminate labeling.

clabel(C,h,'manual') places contour labels at locations you select with a mouse. Press the Return key while the cursor is within the figure window to terminate labeling. The labels are rotated and inserted in the contour lines.

example

text_handles = clabel(___) additionally returns an array containing the handles of the text objects created, using any of the input arguments in the previous syntaxes. If you call clabel without the h argument, text_handles also contains the handles of line objects used to create the '+' symbols.

Examples

expand all

Label Contour Plot with Vertical Text and '+' Symbols

Generate a contour plot and obtain the contour matrix, C.

[x,y,z] = peaks;
figure
C = contour(x,y,z);

Label the contour plot.

clabel(C)

Label Contour Plot with Rotated Text Inserted in Contour Lines

Generate a contour plot and obtain the contour matrix, C, and the handle to the contourgroup object, h.

[x,y,z] = peaks;
figure
[C,h] = contour(x,y,z);

Label the contour plot.

clabel(C,h);

Label Specific Contour Levels

Label only the contours with contour levels 2 or 6.

[x,y,z] = peaks;
figure
[C,h] = contour(x,y,z);
v = [2,6];
clabel(C,h,v)

Set Label Spacing

Set the label spacing to 72 points (1 inch).

[x,y,z] = peaks;
figure
[C,h] = contour(x,y,z);
clabel(C,h,'LabelSpacing',72)

Label Contour Plot and Set Text Properties

Use Name,Value arguments to set the font size, font color, and text orientation of the labels.

[x,y,z] = peaks;
figure
[C,h] = contour(x,y,z);
clabel(C,h,'FontSize',15,'Color','r','Rotation',0)

'FontSize',15,'Color','r' adds 15-point red labels to the contour plot. 'Rotation',0 makes the text upright.

Label Contour Plot and Return Object Handles

Label a contour plot and return the handles of the objects created.

[x,y,z] = peaks;
figure
[C,h] = contour(x,y,z);
text_handles = clabel(C,h);

MATLAB® returns an array containing the handles of the text objects created.

Set the color of the labels to blue, using the handle to the text objects.

set(text_handles,'Color','blue')

Input Arguments

expand all

C — Contour matrix2-by-n matrix

Contour matrix containing the data that defines the contour lines. C is returned by the contour, contour3, or contourf function.

h — Handle to the contourgroup objectvalue returned by contour functions

Handle to the contourgroup object specified as the value returned by the contour, contour3, or contourf function.

v — Contour level valuesvector

Contour level values, specified as a row or column vector of individual values.

Example: [0,10,20]

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.

Example: 'Color','red','Rotation',45 adds red labels to a contour plot, where each label is rotated 45 degrees.

In addition to the following, you can specify other text object properties using Name,Value pair arguments. See Text Properties.

'Color' — Text color[0 0 0] (black) (default) | 3-element RGB vector | string

Text color, specified as the comma-separated pair consisting of 'Color' and a 3-element RGB vector or a string containing the short or long name of the color. The RGB vector is a 3-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0 1].

The following table lists the predefined colors and their RGB equivalents.

RGB Value

Short Name

Long Name

[1 1 0]

y

yellow

[1 0 1]

m

magenta

[0 1 1]

c

cyan

[1 0 0]

r

red

[0 1 0]

g

green

[0 0 1]

b

blue

[1 1 1]

w

white

[0 0 0]

k

black

Example: 'Color',[0 1 0]

Example: 'Color','green'

'FontName' — Font name'Helvetica' (default) | string | 'FixedWidth'

Font name, specified as the comma-separated pair consisting of 'FontName' and a string. The string specifies the name of the font to use for the text object. To display and print properly, this must be a font that your system supports.

To use a fixed-width font that looks good in any locale, use the case-sensitive string 'FixedWidth'. This eliminates the need to hard-code the name of a fixed-width font, which might not display text properly on systems that do not use ASCII character encoding.

Example: 'FontName','Courier'

'FontSize' — Font size10 points (default) | scalar

Font size, specified as the comma-separated pair consisting of 'FontSize' and a scalar in units determined by the FontUnits property. The default value for FontUnits is points.

Example: 'FontSize',12.5

'FontUnits' — Font size units'points' (default) | 'normalized' | 'inches' | 'centimeters' | 'pixels'

Font size units, specified as the comma-separated pair consisting of 'FontUnits' and one of the following strings:

  • 'points'

  • 'normalized'

  • 'inches'

  • 'centimeters'

  • 'pixels'

When the value of FontUnits is 'normalized', MATLAB® interprets the value of FontSize as a fraction of the height of the parent axes. When you resize the axes, MATLAB modifies the screen FontSize accordingly. points, inches, centimeters, and pixels are absolute units. 1 point = 1/72 inch

    Note:   When setting both the FontSize and the FontUnits, you must set the FontUnits property first so that MATLAB can correctly interpret the specified FontSize. For example, to set the font size to 0.3 inches, call 'FontUnits','inches','FontSize',0.3 in the argument list.

'FontWeight' — Weight of text characters'normal' (default) | 'bold' | 'light' | 'demi'

Weight of text characters, specified as the comma-separated pair consisting of 'FontWeight' and one of the following strings:

  • 'normal'

  • 'bold'

  • 'light'

  • 'demi'

MATLAB uses the FontWeight property to select a font from those available on your particular system. Generally, setting this property to 'bold' or 'demi' causes MATLAB to use a bold font.

Example: 'FontWeight','bold'

'LabelSpacing' — Spacing between labels144 (default) | scalar

Spacing between labels on each contour line, specified as the comma-separated pair consisting of 'LabelSpacing' and a scalar. Specify the label spacing in points, where 1 point = 1/72 inch.

Example: 'LabelSpacing',72

'Rotation' — Text orientation0 (default) | scalar

Text orientation, specified as the comma-separated pair consisting of 'Rotation' and a scalar. Specify values of rotation in degrees. Positive values result in counterclockwise rotation.

Example: 'Rotation',45

Output Arguments

expand all

text_handles — Handles of text objectshandle

Handles of the text objects that clabel creates. The UserData properties of the text objects contain the contour values displayed.

If you call clabel without the h argument, text_handles also contains the handles of line objects used to create the '+' symbols.

More About

See Also

| | |

Was this topic helpful?