textm
Project text onto axesm
-based map
Description
textm(
projects the text in lat
,lon
,txt
)txt
onto the current
axesm
-based map at the latitude-longitude locations specified by
lat
and lon
. To add text to one point, specify
lat
and lon
as scalars. To add text to multiple
points, specify lat
and lon
as vectors of equal
length.
To add text to geographic axes or map axes, use the text
function instead.
textm(___,
specifies
options for the text using one or more name-value arguments, in addition to any combination
of arguments from previous syntaxes.. For example, Name,Value
)"FontSize",14
sets the
font size to 14 points.
returns one or more
t
= textm(___)Text
objects, in addition to any combination of arguments from previous
syntaxes. Use t
to modify properties of the Text
objects after creation. For a list of properties and descriptions, see Text Properties.
Examples
Add Text Description to Map
Import a shapefile containing USA state polygons into the workspace as a geospatial table. Create a map of Texas.
GT = readgeotable("usastatehi.shp"); usamap texas geoshow(GT)
Label the city of Austin by adding a star marker and a text description.
lat = 30.2672; lon = -97.7431; geoshow(lat,lon,"Marker","*") textm(lat,lon," Austin, TX")
Add Text to Multiple Data Points
Import a shapefile containing USA state polygons into the workspace as a geospatial table. Create a map of Oregon, Idaho, and Washington.
GT = readgeotable("usastatehi.shp"); usamap(["OR" "ID" "WA"]) geoshow(GT)
Label the states by adding text.
lat = [43.86 44.01 47.59]; lon = [-121.56 -115.12 -121.42]; txt = ["Oregon" "Idaho" "Washington"]; textm(lat,lon,txt)
Display Multiline Text
Import a shapefile containing world land areas into the workspace as a geospatial table. Create a map.
GT = readgeotable("landareas.shp"); worldmap world geoshow(GT)
Add one text description to the map. Display multiline text by specifying txt
as a string array.
txt = ["A map of" "the world"]; textm(-40,60,txt)
Specify Text Color and Size
Import a shapefile containing USA state polygons into the workspace as a geospatial table. Create a map of Oregon, Idaho, and Washington.
GT = readgeotable("usastatehi.shp"); usamap(["OR" "ID" "WA"]) geoshow(GT)
Label the states by adding text. Use red, size 14 font.
lat = [43.86 44.01 47.25]; lon = [-121.56 -115.12 -122.15]; txt = ["Oregon" "Idaho" "Washington"]; textm(lat,lon,txt,"Color","red","FontSize",14)
Modify Existing Text
Import a shapefile containing USA state polygons into the workspace as a geospatial table. Create a map of Oregon, Idaho, and Washington.
GT = readgeotable("usastatehi.shp"); usamap(["OR" "ID" "WA"]) geoshow(GT)
Label the states by adding text. Return the text objects in t
.
lat = [43.86 44.01 47.25]; lon = [-121.56 -115.12 -122.15]; txt = ["Oregon" "Idaho" "Washington"]; t = textm(lat,lon,txt)
t = 3x1 Text array: Text (Oregon) Text (Idaho) Text (Washington)
The textm
function creates one text object for each text description. Thus, t
contains three text objects.
Change the color and font size for the first text object using t(1)
.
t(1).Color = "red";
t(1).FontSize = 14;
Input Arguments
lat
— Latitude coordinates
numeric scalar | numeric vector
Latitude coordinates, specified in one of these forms:
Numeric scalar — Add text to a single point.
Numeric vector — Add text to multiple points.
The units of lat
must match the AngleUnits
property of the axesm
-based map. The sizes of
lat
and lon
must match.
To control the placement of the text with relation to the specified point, use the
HorizontalAlignment
, VerticalAlignment
, and Extent
properties of the
Text
object.
Data Types: single
| double
lon
— Longitude coordinates
numeric scalar | numeric vector
Longitude coordinates, specified in one of these forms:
Numeric scalar — Add text to a single point.
Numeric vector — Add text to multiple points.
The units of lon
must match the AngleUnits
property of the axesm
-based map. The sizes of
lat
and lon
must match.
To control the placement of the text with relation to the specified point, use the
HorizontalAlignment
, VerticalAlignment
, and Extent
properties of the
Text
object.
Data Types: single
| double
z
— Altitudes
0
(default) | numeric scalar | numeric vector
Altitudes, specified in one of these forms:
Numeric scalar — Add text to a single point.
Numeric vector — Add text to multiple points.
When the MapProjection
property of the
axesm
-based map is 'globe'
,
z
is referenced to the ellipsoid.
The sizes of lat
, lon
, and
z
must match.
To control the placement of the text with relation to the specified point, use the
HorizontalAlignment
, VerticalAlignment
, and Extent
properties of the
Text
object.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| categorical
| datetime
| duration
txt
— Text to display
character vector | string scalar | string array | cell array of character vectors
Text to display, specified as a character vector, string scalar, string array, or cell array of character vectors.
Text for Single Data Point
To add one line of text to a single point, specify txt
as a
character vector or string scalar. For example, textm(0.5,0.5,'my
text')
.
For multiline text:
Use a cell array, where each cell contains a line of text. For example,
textm(0.5,0.5,{'first','second'})
.Use a string array, where each element is a line of text. For example,
textm(0.5,0.5,["first","second"])
.Use
sprintf
to create a new line character. For example,textm(0.5,0.5,sprintf('first \nsecond'))
.
Text for Multiple Data Points
To display different text at each location, use a cell array. For example,
textm([0 1],[0 1],{'first','second'})
.
For multiline text, use nested cell arrays. For example, textm([0 3],[0
3],{{'first','new line'},'second'})
.
Greek Letters, Special Characters, and Numeric Variables
To include special characters, such as superscripts, subscripts, Greek letters, or
mathematical symbols, use TeX markup. For a list of supported markup, see the
Interpreter
property
of the Text
object.
To include numeric variables in the text, use the num2str
function.
v = 42;
txt = ['The value is ',num2str(v)];
Data Types: char
| string
| cell
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: textm(0.5,0.5,"my text","FontSize",14,"Color","red")
displays
my text
with a font size of 14 and a font color of red.
Note
Use name-value arguments to specify values for the properties of the
Text
objects created by this function. The properties listed here are
only a subset. For a full list, see Text Properties.
FontSize
— Font size
scalar value greater than zero
Font size, specified as a scalar value greater than zero in point units. The
default font size depends on the specific operating system and locale. 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
FontWeight
— Character thickness
'normal'
(default) | 'bold'
Character thickness, specified as 'normal'
or
'bold'
.
MATLAB® uses the FontWeight
property to select a font from
those available on your system. Not all fonts have a bold weight. Therefore,
specifying a bold font weight can still result in the normal font weight.
FontName
— Font name
supported font name | 'FixedWidth'
Font name, specified as a supported font name or 'FixedWidth'
.
To display and print text properly, you must choose a font that your system supports.
The default font depends on your operating system and locale.
To use a fixed-width font that looks good in any locale, use
'FixedWidth'
. The fixed-width font relies on the root FixedWidthFontName
property. Setting the root FixedWidthFontName
property causes an
immediate update of the display to use the new font.
Color
— Text color
[0 0 0]
(default) | RGB triplet | hexadecimal color code | 'r'
| 'g'
| 'b'
| ...
Text color, specified as an RGB triplet, a hexadecimal color code, a color name,
or a short name. The default value of [0 0 0]
corresponds to
black.
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: 'blue'
Example: [0 0 1]
Example: '#0000FF'
Output Arguments
t
— Text
objects
Text
objects
Text
objects. Use the elements of t
to modify
a specific Text
object after creation. For a list of properties, see
Text Properties.
To change the position of a Text
object by specifying geographic
coordinates, use the setm
function.
Tips
The words "default"
, "remove"
, and
"factory"
are reserved words in MATLAB. To create text using one of these words, append a backslash
(\
) before the word. For example,
textm(0.5,0.5,"\default")
.
Version History
Introduced before R2006a
See Also
Functions
Properties
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
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
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)