Main Content

plot3m

Project 3-D lines and points on axesm-based map

    Description

    plot3m(lat,lon,z) projects the lines specified by lat, lon, and z onto the current axesm-based map.

    example

    plot3m(lat,lon,z,LineSpec) creates the plot using the specified line style, marker, and color.

    plot3m(lat,lon,z,Name,Value) specifies line properties using one or more name-value pair arguments. For example, "Color","red" creates a red plot.

    p = plot3m(___) returns the line objects. Use p to modify the plot after it is created. For a list of properties, see Line Properties.

    Examples

    collapse all

    Read sample data containing the latitude, longitude, and height coordinates of a UAV. Find the latitude and longitude limits of the data, including a latitude-longitude buffer of 0.02 degrees.

    GT = readgeotable("sample_uavtrack.gpx","Layer","track_points");
    lat = GT.Shape.Latitude;
    lon = GT.Shape.Longitude;
    h = GT.Elevation;
    
    [latlim,lonlim] = geoquadline(lat,lon);
    [latlim,lonlim] = bufgeoquad(latlim,lonlim,0.02,0.02);

    Read terrain elevation data, in meters, for the region from the Web Map Service (WMS) server hosted by MathWorks®.

    layers = wmsfind("mathworks","SearchField","serverurl");
    elevation = refine(layers,"elevation");
    [Z,R] = wmsread(elevation,"Latlim",latlim,"Lonlim",lonlim, ...
        "ImageFormat","image/bil");
    Z = double(Z);

    Prepare an axesm-based map of the region. Remove all labels and grid lines.

    figure
    usamap(Z,R)
    framem off
    mlabel off
    plabel off
    gridm off

    Display the terrain elevation data as a surface. Specify a colormap appropriate for elevation data.

    geoshow(Z,R,"DisplayType","surface")
    demcmap(Z)

    Plot the terrain elevation data over the surface.

    plot3m(lat,lon,h,"k")

    View the map in 3-D. Vertically exaggerate the terrain by a factor of 5.

    view([-130 15])
    daspectm("meters",5)

    Read two data sets into the workspace:

    • A grid of world geoid heights from the Earth Gravitational Model of 1996. The variable N specifies geoid heights in meters, and the variable R is the spatial reference for N.

    • A MAT file containing global coastline coordinates. The variables within the MAT file, coastlat and coastlon, specify latitude and longitude coordinates, respectively.

    [N,R] = egm96geoid;
    load coastlines

    Create a world map.

    figure
    worldmap world
    plabel off
    mlabel off

    Display the geoid heights as a 3-D surface. Then, display the coastline coordinates as a 2-D black line.

    geoshow(N,R,"DisplayType","surface")
    plotm(coastlat,coastlon,"k")

    In some places, the coastlines are obscured by the surface. Display the coastline coordinates again, this time using a 3-D line. Specify the height of the line using a value that is 1 meter more than the maximum geoid height.

    h = max(max(N)) + 1;
    plot3m(coastlat,coastlon,h,"k")

    Input Arguments

    collapse all

    Latitude coordinates, specified as a scalar, vector, or matrix. The sizes of lat and lon must match. Specify lat in the units indicated by the AngleUnits property of the axesm-based map.

    The size and shape of lat depends on the type of plot you want to create.

    Type of PlotHow to Specify Coordinates
    Single point

    Specify lat, lon, and z as scalars and include a marker. For example:

    plot3m(1,2,3,"o")

    One set of points

    Specify lat and lon as vectors of the same length. Specify z as a scalar or as a vector of the same length as lat and lon. For example:

    plot3m([1 2 3],[4 5 6],[7 8 9])

    Multiple sets of points (using vectors)

    Specify lat and lon as vectors of the same length. Specify z as a scalar or as a vector of the same length as lat and lon. Use NaN values to separate the sets of points. For example:

    plot3m([1 2 3 NaN 1 2 3],[4 5 6 NaN 7 8 9],[10 11 12 NaN 13 14 15])

    Multiple sets of points (using matrices)

    Specify lat and lon as matrices of the same size. Specify z as a scalar or as a matrix of the same size as lat and lon. For example:

    plot3m([1 2 3; 1 2 3],[4 5 6; 7 8 9],[10 11 12; 13 14 15])

    Data Types: double

    Longitude coordinates, specified as a scalar, vector, or matrix. The sizes of lon and lat must match. Specify lon in the units indicated by the AngleUnits property of the axesm-based map.

    The size and shape of lon depends on the type of plot you want to create.

    Type of PlotHow to Specify Coordinates
    Single point

    Specify lat, lon, and z as scalars and include a marker. For example:

    plot3m(1,2,3,"o")

    One set of points

    Specify lat and lon as vectors of the same length. Specify z as a scalar or as a vector of the same length as lat and lon. For example:

    plot3m([1 2 3],[4 5 6],[7 8 9])

    Multiple sets of points (using vectors)

    Specify lat and lon as vectors of the same length. Specify z as a scalar or as a vector of the same length as lat and lon. Use NaN values to separate the sets of points. For example:

    plot3m([1 2 3 NaN 1 2 3],[4 5 6 NaN 7 8 9],[10 11 12 NaN 13 14 15])

    Multiple sets of points (using matrices)

    Specify lat and lon as matrices of the same size. Specify z as a scalar or as a matrix of the same size as lat and lon. For example:

    plot3m([1 2 3; 1 2 3],[4 5 6; 7 8 9],[10 11 12; 13 14 15])

    Data Types: double

    Heights, specified as a scalar, a vector of the same size as lat and lon, or a matrix of the same size as lat and lon.

    In most cases, the units of z are arbitrary. When the MapProjection property of the axesm-based map is "globe", z is referenced to the ellipsoid. In this case, specify z using the length unit of the ellipsoid.

    Data Types: double

    Line style, marker, and color, specified as a string scalar or character vector containing symbols. The symbols can appear in any order. You do not need to specify all three characteristics (line style, marker, and color). For example, if you omit the line style and specify the marker, then the plot shows only the marker and no line.

    Example: "--or" is a red dashed line with circle markers.

    Line StyleDescriptionResulting Line
    "-"Solid line

    Sample of solid line

    "--"Dashed line

    Sample of dashed line

    ":"Dotted line

    Sample of dotted line

    "-."Dash-dotted line

    Sample of dash-dotted line, with alternating dashes and dots

    MarkerDescriptionResulting Marker
    "o"Circle

    Sample of circle marker

    "+"Plus sign

    Sample of plus sign marker

    "*"Asterisk

    Sample of asterisk marker

    "."Point

    Sample of point marker

    "x"Cross

    Sample of cross marker

    "_"Horizontal line

    Sample of horizontal line marker

    "|"Vertical line

    Sample of vertical line marker

    "square"Square

    Sample of square marker

    "diamond"Diamond

    Sample of diamond marker

    "^"Upward-pointing triangle

    Sample of upward-pointing triangle marker

    "v"Downward-pointing triangle

    Sample of downward-pointing triangle marker

    ">"Right-pointing triangle

    Sample of right-pointing triangle marker

    "<"Left-pointing triangle

    Sample of left-pointing triangle marker

    "pentagram"Pentagram

    Sample of pentagram marker

    "hexagram"Hexagram

    Sample of hexagram marker

    Color NameShort NameRGB TripletAppearance
    "red""r"[1 0 0]

    Sample of the color red

    "green""g"[0 1 0]

    Sample of the color green

    "blue""b"[0 0 1]

    Sample of the color blue

    "cyan" "c"[0 1 1]

    Sample of the color cyan

    "magenta""m"[1 0 1]

    Sample of the color magenta

    "yellow""y"[1 1 0]

    Sample of the color yellow

    "black""k"[0 0 0]

    Sample of the color black

    "white""w"[1 1 1]

    Sample of the color white

    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.

    Example: plot3m(lat,lon,z,LineStyle="--") displays dashed lines.

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: plot3m(lat,lon,z,"LineStyle","--") displays dashed lines.

    Note

    Use name-value arguments to specify values for the properties of the Line object created by this function. The properties listed here are only a subset. For a full list, see Line Properties.

    Setting the XData, YData, and ZData properties of the line object is not supported.

    Color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name. The color you specify sets the line color. It also sets the marker edge color when the MarkerEdgeColor property is set to 'auto'.

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

    Line width, specified as a positive value in points, where 1 point = 1/72 of an inch. If the line has markers, then the line width also affects the marker edges.

    The line width cannot be thinner than the width of a pixel. If you set the line width to a value that is less than the width of a pixel on your system, the line displays as one pixel wide.

    Marker size, specified as a positive value in points, where 1 point = 1/72 of an inch.

    Marker outline color, specified as "auto", an RGB triplet, a hexadecimal color code, a color name, or a short name. The default value of "auto" uses the same color as the Color property.

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

    Marker fill color, specified as "auto", an RGB triplet, a hexadecimal color code, a color name, or a short name. The "auto" option uses the same color as the Color property of the parent axes. If you specify "auto" and the axes plot box is invisible, the marker fill color is the color of the figure.

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

    Output Arguments

    collapse all

    Line objects, returned as an array of Line objects. Use p to modify the Line objects after creation. For a list of properties, see Line Properties.

    Setting the XData, YData, and ZData properties of the line objects is not supported.

    Version History

    Introduced before R2006a

    See Also

    Functions