Main Content

textm

Project text onto axesm-based map

    Description

    example

    textm(lat,lon,txt) projects the text in 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, use the text function instead.

    textm(lat,lon,z,txt) positions the text at the altitudes in z.

    example

    textm(___,Name,Value) specifies options for the text using one or more name-value arguments, in addition to any combination of arguments from previous syntaxes.. For example, "FontSize",14 sets the font size to 14 points.

    example

    t = textm(___) returns one or more 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

    collapse all

    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")

    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)

    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)

    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)

    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

    collapse all

    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

    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

    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

    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.

    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

    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.

    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.

    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 character vector or a string scalar that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. 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 NameShort NameRGB TripletHexadecimal Color CodeAppearance
    "red""r"[1 0 0]"#FF0000"

    Sample of the color red

    "green""g"[0 1 0]"#00FF00"

    Sample of the color green

    "blue""b"[0 0 1]"#0000FF"

    Sample of the color blue

    "cyan" "c"[0 1 1]"#00FFFF"

    Sample of the color cyan

    "magenta""m"[1 0 1]"#FF00FF"

    Sample of the color magenta

    "yellow""y"[1 1 0]"#FFFF00"

    Sample of the color yellow

    "black""k"[0 0 0]"#000000"

    Sample of the color black

    "white""w"[1 1 1]"#FFFFFF"

    Sample of the color white

    "none"Not applicableNot applicableNot applicableNo color

    Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

    RGB TripletHexadecimal Color CodeAppearance
    [0 0.4470 0.7410]"#0072BD"

    Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

    [0.8500 0.3250 0.0980]"#D95319"

    Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

    [0.9290 0.6940 0.1250]"#EDB120"

    Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

    [0.4940 0.1840 0.5560]"#7E2F8E"

    Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

    [0.4660 0.6740 0.1880]"#77AC30"

    Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

    [0.3010 0.7450 0.9330]"#4DBEEE"

    Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

    [0.6350 0.0780 0.1840]"#A2142F"

    Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

    Example: 'blue'

    Example: [0 0 1]

    Example: '#0000FF'

    Output Arguments

    collapse all

    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