Label contour plot elevation
collapse all in page
Syntax
clabel(C,h)
clabel(C,h,v)
clabel(C,h,'manual')
t = clabel(C,h,'manual')
clabel(C)
clabel(C,v)
clabel(C,'manual')
tl = clabel(___)
clabel(___,Name,Value)
Description
example
clabel(C,h)
labelsthe current contour plot with rotated text inserted into each contourline. The contour lines must be long enough to fit the label, otherwise clabel
doesnot insert a label. If you do not have the contour matrix C
,then replace C
with []
.
example
clabel(C,h,v)
labelsthe contour levels specified by vector v
.
clabel(C,h,'manual')
labelsthe locations you select with the mouse. Click the mouse or pressthe space bar to label the contour closest to the center of the crosshair.Press the Return key while the cursor is within thefigure window to terminate labeling.
t = clabel(C,h,'manual')
returnsthe text objects created.
example
clabel(C)
labels contourswith '+'
symbols and upright text.
clabel(C,v)
addsupright labels to the contour levels specified by the vector, v
.
clabel(C,'manual')
addsupright labels at the locations you select with the mouse. Click themouse or press the space bar to label the contour closest to the centerof the crosshair. Press the Return key while thecursor is within the figure window to terminate labeling.
tl = clabel(___)
returnsthe text and line objects created. Use any of the input argument combinationsin the previous syntaxes that do not include the contour object h
.
example
clabel(___,Name,Value)
modifiesthe label appearance using one or more Name,Value
pairarguments. Use any of the input argument combinations in the previoussyntaxes. For example, 'FontSize',14
sets the fontsize to 14 points.
Examples
collapse all
Label Contour Plot Levels
Open Live Script
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
Open Live Script
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 Properties
Open Live Script
Set the font size of the labels to 15 points and set the color to red using Name,Value
pair arguments.
[x,y,z] = peaks;[C,h] = contour(x,y,z);clabel(C,h,'FontSize',15,'Color','red')
Set additional properties by reissuing the clabel
command. For example, set the font weight to bold and change the color to blue.
clabel(C,h,'FontWeight','bold','Color','blue')
Set the font size back to the default size using the 'default'
keyword.
clabel(C,h,'FontSize','default')
Label Contour Plot with Vertical Text
Open Live Script
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)
Input Arguments
collapse all
C
— Contour matrix
two-row matrix
Contour matrix returned by the contour
, contour3
, or contourf
function. C
contains the data that defines the contour lines. For more information on the contour matrix, see ContourMatrix.
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 object
contour object
Contour object returned by the contour
, contour3
,or contourf
function.
v
— Contour level values
vector
Contour level values, specified as a row or column vector ofindividual values.
Example: [0 10 20]
Name-Value Arguments
Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: clabel(C,h,'Color','red','FontSize',12)
specifiesred, 12-point labels.
clabel
supports the LabelSpacing
propertyplus a subset of text properties.
LabelSpacing
— Space between labels
scalar
Space between labels, specified as a scalar value in point units.
Note
Use this option with either the clabel(C,h)
or clabel(C,h,v)
syntax.Other syntaxes do not support this option.
Example: clabel(C,h,'LabelSpacing',100)
EdgeColor
— Color of text box outline
'none'
(default) | RGB triplet | hexadecimal color code | 'r'
| 'g'
| 'b'
| ...
Color of text box outline, specified as 'none'
, an RGB triplet, a hexadecimal color code, a color name, or a short name.
For a custom color, specify an RGB triplet or a hexadecimal color code.
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]
.A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (
#
) followed by three or six hexadecimal digits, which can range from0
toF
. The values are not case sensitive. Therefore, the color codes"#FF8800"
,"#ff8800"
,"#F80"
, and"#f80"
are equivalent.
Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
Color Name | Short Name | RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|---|---|
"red" | "r" | [1 0 0] | "#FF0000" | |
"green" | "g" | [0 1 0] | "#00FF00" | |
"blue" | "b" | [0 0 1] | "#0000FF" | |
"cyan" | "c" | [0 1 1] | "#00FFFF" | |
"magenta" | "m" | [1 0 1] | "#FF00FF" | |
"yellow" | "y" | [1 1 0] | "#FFFF00" | |
"black" | "k" | [0 0 0] | "#000000" | |
"white" | "w" | [1 1 1] | "#FFFFFF" | |
"none" | Not applicable | Not applicable | Not applicable | No color |
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.
RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|
[0 0.4470 0.7410] | "#0072BD" | |
[0.8500 0.3250 0.0980] | "#D95319" | |
[0.9290 0.6940 0.1250] | "#EDB120" | |
[0.4940 0.1840 0.5560] | "#7E2F8E" | |
[0.4660 0.6740 0.1880] | "#77AC30" | |
[0.3010 0.7450 0.9330] | "#4DBEEE" | |
[0.6350 0.0780 0.1840] | "#A2142F" |
Example: clabel(C,h,'EdgeColor','k')
BackgroundColor
— Background color
'none'
(default) | RGB triplet | hexadecimal color code | 'r'
| 'g'
| 'b'
| ...
Color of text box background, specified as 'none'
, an RGB triplet, hexadecimal color code, a color name, or a short name.
For a custom color, specify an RGB triplet or a hexadecimal color code.
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]
.A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (
#
) followed by three or six hexadecimal digits, which can range from0
toF
. The values are not case sensitive. Therefore, the color codes"#FF8800"
,"#ff8800"
,"#F80"
, and"#f80"
are equivalent.
Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
Color Name | Short Name | RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|---|---|
"red" | "r" | [1 0 0] | "#FF0000" | |
"green" | "g" | [0 1 0] | "#00FF00" | |
"blue" | "b" | [0 0 1] | "#0000FF" | |
"cyan" | "c" | [0 1 1] | "#00FFFF" | |
"magenta" | "m" | [1 0 1] | "#FF00FF" | |
"yellow" | "y" | [1 1 0] | "#FFFF00" | |
"black" | "k" | [0 0 0] | "#000000" | |
"white" | "w" | [1 1 1] | "#FFFFFF" | |
"none" | Not applicable | Not applicable | Not applicable | No color |
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.
RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|
[0 0.4470 0.7410] | "#0072BD" | |
[0.8500 0.3250 0.0980] | "#D95319" | |
[0.9290 0.6940 0.1250] | "#EDB120" | |
[0.4940 0.1840 0.5560] | "#7E2F8E" | |
[0.4660 0.6740 0.1880] | "#77AC30" | |
[0.3010 0.7450 0.9330] | "#4DBEEE" | |
[0.6350 0.0780 0.1840] | "#A2142F" |
Example: clabel(C,h,'BackgroundColor','g')
FontSize
— Font size
10
(default) | scalar value greater than 0
Font size, specified as a scalar value greater than 0. By default,the font size uses point units. One point equals 1/72 inch. However,some syntaxes allow you to change the font units using the FontUnits property.
Example: clabel(C,h,'FontSize',15)
FontSmoothing
— Font smoothing
'on'
(default) | on/off logical value
Font smoothing, specified as 'on'
or 'off'
, or as numeric or logical 1
(true
) or 0
(false
). A value of 'on'
is equivalent to true
, and 'off'
is equivalent to false
. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.
'on'
— Apply font smoothing. Reduce the appearance of jaggedness in the text characters to make the text easier to read.'off'
— Do not apply font smoothing.
Example: clabel(C,h,'FontSmoothing','on')
Note
The FontSmoothing
name-value argument will have no effect in a future release. Font smoothing will be enabled regardless of the value.
FontUnits
— Font size units
'points'
(default) | 'inches'
| 'centimeters'
| 'characters'
| 'normalized'
| 'pixels'
Font size units, specified as one of the values in this table.
Units | Description |
---|---|
'points' | Points. One point equals 1/72 inch. |
'inches' | Inches. |
'centimeters' | Centimeters. |
'characters' | Based on the default system font character size.
|
'normalized' | Interpret font size as a fraction of the axes height. If youresize the axes, the font size modifies accordingly. For example,if the FontSize is 0.1 in normalizedunits, then the text is 1/10 of the axes height. |
'pixels' | Pixels. Starting in R2015b, distances inpixels are independent of your system resolution on Windows® and Macintosh systems:
On Linux® systems, the size of a pixel is determinedby your system resolution. |
If you set both the font size and the font units in one functioncall, you must set the FontUnits
property firstso that the axes correctly interprets the specified font size.
Note
The clabel(C,h)
and clabel(C,h,v)
syntaxesdo not support this option. They always use the default value of points.
Example: clabel(C,'FontUnits','normalized')
Rotation
— Text orientation
0
(default) | scalar
Text orientation, specified as a scalar value in degrees. Thedefault rotation of 0 degrees makes the text horizontal. For verticaltext, set this property to 90
or -90
.Positive values rotate the text counterclockwise. Negative valuesrotate the text clockwise.
Note
The clabel(C,h)
and clabel(C,h,v)
syntaxesdo not support this option. Instead, they insert rotated text intothe contour lines, with each label rotated to match the local orientationof the corresponding line.
Example: clabel(C,'Rotation',90)
Interpreter
— Interpretation of text characters
'tex'
(default) | 'latex'
| 'none'
Interpretation of text characters, specified as one of thesevalues:
'tex'
— Display text usingTeX markup.'latex'
— Display text usingLaTeX markup.'none'
— Display literalcharacters.
Since the labels are numeric text, the effect of this propertyis limited to subtle changes in the font style and weight.
Example: clabel(C,h,'Interpreter','latex')
LineStyle
— Line style of text box outline
'-'
(default) | '--'
| ':'
| '-.'
| 'none'
Line style of text box outline, specified as one of the linestyles in this table.
Line Style | Description | Resulting Line |
---|---|---|
"-" | Solid line | |
"--" | Dashed line | |
":" | Dotted line | |
"-." | Dash-dotted line | |
"none" | No line | No line |
Example: clabel(C,h,'LineStyle','--')
LineWidth
— Width of text box outline
0.5
(default) | scalar
Width of text box outline, specified as a scalar value in pointunits. One point equals 1/72 inch.
Example: clabel(C,h,'LineWidth',1)
Margin
— Space around text within the text box
3
(default) | scalar
The space around the text within the text box, specified asscalar value in point units.
MATLAB uses the Extent
property valueplus the Margin
property value to determine thesize of the text box.
Example: clabel(C,h,'Margin',4)
Output Arguments
collapse all
t
— Text objects
vector
Text objects, returned as a vector. The String
propertiesof the text objects contain the contour values displayed.
tl
— Text and line objects
vector
Text and line objects, returned as a vector. The String
propertiesof the text objects contain the contour values displayed. The lineobjects correspond to the '+'
symbols.
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
This function accepts GPU arrays, but does not run on a GPU.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
Usage notes and limitations:
This function operates on distributed arrays, but executes in the client MATLAB.
For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a
expand all
R2023b: Setting Color
name-value argument also sets LabelColor
of Contour
object
If you set the Color
name-value argument when you call the clabel
function, the LabelColor
property of the Contour
object updates to the specified color value.
R2022a: FontSmoothing
will have no effect in a future release
The FontSmoothing
name-value argument will have no effect in a future release. Font smoothing will be enabled for all contour labels regardless of the value of the argument.
See Also
Functions
- contour | contourc | contourf | contour3
Properties
- Text Properties
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本 (日本語)
- 한국 (한국어)
Contact your local office