clabel

Contour plot elevation labels

Syntax

  • clabel(C) example
  • clabel(C,v)
  • clabel(C,'manual')
  • clabel(___,Name,Value) example
  • tl = clabel(___)

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.

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

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.

example

clabel(___,Name,Value) specifies text properties using one or more Name,Value pair arguments. Use this option with any of the input argument combinations in the previous syntaxes. For example, 'FontSize',14 sets the font size to 14 points.

tl = clabel(___) returns the text and line objects created.

example

clabel(C,h) inserts rotated labels into each contour line. The contour line must be long enough to fit the label, otherwise clabel does not insert a label. If you do not have the contour matrix C, then replace C with [].

example

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

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.

example

clabel(___,'LabelSpacing',space) specifies the spacing between labels as a scalar value. Use this option with any of the input argument combinations that use both the contour matrix C and the contour object h. For example, clabel(C,h,'LabelSpacing',72) spaces the labels 72 points apart (1 inch).

Examples

expand all

Label Contour Plot with Vertical Text

Create a contour plot and return the contour matrix, C. Then, label the contours.

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

Label Contour Plot with Rotated Text

Create a contour plot and obtain the contour matrix, C, and the contour object, h. Then, label the contour plot.

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

Label Specific Contour Levels

Label only the contours with contour levels 2 or 6.

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

Set Contour Label Spacing

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

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

Set Contour Label Text Properties

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

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

Set Contour Label Text Properties After Creation

Label the contour lines at level 2 and 6. Return the text and line objects created.

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

The output tl is a vector that contains one text object and one line object for each contour label.

disp(tl)
  6x1 graphics array:

  Line
  Text    (2)
  Line
  Text    (2)
  Line
  Text    (6)

Change the font size for one of the labels. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead.

tl(2).FontSize = 20;

Input Arguments

expand all

C — Contour matrixtwo-row matrix

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

    Note:   If you pass the contour object h to the clabel function, then you can replace C with []. For example, use clabel([],h).

h — Contour objectcontour object

Contour object 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]

space — Space between labelsscalar

Space between labels, specified as a scalar in point units.

Example: 72

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 specifies red labels rotated 45 degrees.

    Note:   Starting in R2014b, you can no longer set text properties if you pass the contour object h as an input argument to the function. For example, clabel(C,h,'Fontsize',14) does not set the font size. Use clabel(C,'FontSize',14) instead.

The text properties listed here are only a subset, for a complete list, see Text Properties.

'FontSize' — Font size10 (default) | scalar value greater than 0

Font size, specified as a scalar value greater than 0 in point units. One point equals 1/72 inch. To change the font units, use the FontUnits property.

Example: 12

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

'FontName' — Font name'Helvetica' (default) | 'FixedWidth' | system supported font name

Font name, specified as the name of the font to use or the string 'FixedWidth'. To display and print properly, the font name 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. The 'FixedWidth' value relies on the root FixedWidthFontName property. Setting the root FixedWidthFontName property causes an immediate update of the display to use the new font.

Example: 'Cambria'

'FontWeight' — Thickness of text characters'normal' (default) | 'bold'

Thickness of the text characters, specified as one of these values:

  • 'normal' — Default weight as defined by the particular font

  • 'bold' — Thicker characters outlines than normal

MATLAB® uses the FontWeight property to select a font from those available on your system. Not all fonts have a bold font weight. Therefore, specifying a bold font weight could still result in the normal font weight.

    Note:   The 'light' and 'demi' font weight values have been removed. Use 'normal' instead.

'Color' — Text color[0 0 0] (default) | RGB triplet | color string | 'none'

Text color, specified as a three-element RGB triplet, a color string, or 'none'. The default color is black with an RGB triplet value of [0 0 0]. If you set the color to 'none', then the text is invisible.

An RGB triplet is a three-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], for example, [0.4 0.6 0.7]. This table lists RGB triplet values that have equivalent color strings.

Long NameShort NameRGB Triplet
'yellow''y'[1 1 0]
'magenta''m'[1 0 1]
'cyan''c'[0 1 1]
'red''r'[1 0 0]
'green''g'[0 1 0]
'blue''b'[0 0 1]
'white''w'[1 1 1]
'black'k'[0 0 0]

Example: 'blue'

Example: [0 0 1]

Output Arguments

expand all

tl — Text and line objectsvector

Text and line objects, returned as a vector. The String properties of the text objects contain the contour values displayed. The line objects correspond to the '+' symbols.

    Note:   Starting in R2014b, you can no longer return the output argument tl if you pass the contour object h as an input argument to the function. For example, tl = clabel(C,h) warns and returns empty. Use tl = clabel(C) instead.

See Also

Functions

Properties

Was this topic helpful?