Main Content

geoplot

Plot line in geographic coordinates

Description

example

geoplot(lat,lon) plots a line in a geographic axes with vertices at the latitude-longitude locations specified (in degrees) by the vectors lat and lon. The lat and lon inputs must be the same size. By default, geoplot draws a solid line, with no markers, using colors specified by the ColorOrder property of the geographic axes object.

example

geoplot(lat,lon,LineSpec) sets the style, marker symbol, and color for the line.

geoplot(lat1,lon1,...,latN,lonN) combines the plots specified by several sets of latitude-longitude locations.

example

geoplot(lat1,lon1,LineSpec1,...,latN,lonN,LineSpecN) combines the plots specified by several sets of latitude-longitude locations, with a separate LineSpec for each line.

example

geoplot(___,Name,Value) specifies properties of the chart line using one or more Name,Value pair arguments.

geoplot(gx,___) plots in the geographic axes specified by gx instead of the current axes.

h = geoplot(___) returns a column vector of Chart Line objects. Each object corresponds to a plotted line. Use h to modify the properties of the Chart line objects.

Examples

collapse all

Plot a straight line between two points on a map. Specify the endpoints of the line using the coordinates of Seattle and Anchorage. Specify latitude and longitude in degrees.

latSeattle = 47.62;
lonSeattle = -122.33;
latAnchorage = 61.20;
lonAnchorage = -149.9;

Plot the data on a map. Customize the appearance of the line using the line specification 'g-*'. Adjust the latitude and longitude limits of the map using geolimits.

geoplot([latSeattle latAnchorage],[lonSeattle lonAnchorage],'g-*')
geolimits([45 62],[-149 -123])

Plot a straight line between two points on a map. Specify the endpoints of the line using the coordinates of Seattle and Anchorage. Specify latitude and longitude in degrees.

latSeattle = 47.62;
lonSeattle = -122.33;
latAnchorage = 61.20;
lonAnchorage = -149.9;

Plot the data using geoplot. Customize the appearance of the line using the line specification 'g-*'. Adjust the latitude and longitude limits of the map using geolimits.

geoplot([latSeattle latAnchorage],[lonSeattle lonAnchorage],'g-*')
geolimits([45 62],[-149 -123])

Identify Anchorage using the text function.

text(latAnchorage,lonAnchorage,'Anchorage');

Identify Seattle using the text function. Adjust the alignment of the text label by specifying properties of the Text object.

text(latSeattle,lonSeattle,'Seattle',...
    'HorizontalAlignment','right',...
    'VerticalAlignment','bottom');

Specify the latitude and longitude coordinates of Seattle, Anchorage, and Point Barrow.

latSeattle = 47.62;
lonSeattle = -122.33;

latAnchorage = 61.20;
lonAnchorage = -149.9;

latPtBarrow = 71.38;
lonPtBarrow = -156.47;

Plot straight lines from Seattle to each of the other two cities. Draw a solid yellow line from Seattle to Anchorage and a dotted blue line between Seattle and Point Barrow. Adjust the latitude and longitude limits of the map using geolimits.

geoplot([latSeattle latAnchorage],[lonSeattle lonAnchorage],'y-',...
    [latSeattle latPtBarrow],[lonSeattle lonPtBarrow],'b:')
geolimits([44 73],[-149 -123])

Label each city on the map using the text function.

text(latAnchorage,lonAnchorage,'Anchorage');
text(latPtBarrow,lonPtBarrow,'Point Barrow');
text(latSeattle,lonSeattle,'Seattle',...
    'VerticalAlignment','bottom');

Plot a straight line between two points on a map. Specify the endpoints of the line using the coordinates of Seattle and Anchorage. Specify latitude and longitude in degrees.

latSeattle = 47.62;
lonSeattle = -122.33;
latAnchorage = 61.20;
lonAnchorage = -149.9;

Plot the data using geoplot. Adjust the latitude and longitude limits of the map using geolimits. Customize the appearance of the line by specifying the LineWidth and Color properties.

geoplot([latSeattle latAnchorage],[lonSeattle lonAnchorage],...
    'LineWidth',2,'Color',[.6 0 0])
geolimits([45 62],[-149 -123])

Plot a straight line between two points on a map. Specify the endpoints of the line using the coordinates of Seattle and Anchorage. Specify latitude and longitude in degrees.

latSeattle = 47.62;
lonSeattle = -122.33;
latAnchorage = 61.20;
lonAnchorage = -149.9;

Plot the data using geoplot. Adjust the latitude and longitude limits of the map using geolimits.

geoplot([latSeattle latAnchorage],[lonSeattle lonAnchorage])
geolimits([45 62],[-149 -123])

Change the basemap used in the plot using the geobasemap function.

geobasemap colorterrain

Input Arguments

collapse all

Latitude coordinates in degrees, specified as a real, numeric, finite vector. The vector can contain embedded NaNs. lat must be the same size as lon.

Example: [43.0327 38.8921 44.0435]

Data Types: single | double

Longitude coordinates in degrees, specified as a real, numeric, finite vector. The vector can contain embedded NaNs. lon must be the same size as lat.

Example: [-107.5556 -77.0269 -72.5565]

Data Types: single | double

Line style, marker, and color, specified as a character vector or string 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

's'Square

Sample of square marker

'd'Diamond

Sample of diamond line 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

'p'Pentagram

Sample of pentagram marker

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

Target geographic axes, specified as a GeographicAxes object.[1] You can modify the appearance and behavior of a GeographicAxes object by setting its properties. For a list of properties, see GeographicAxes Properties.

Name-Value 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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: h = geoplot(lat,lon,'Color','g')

Note

Property settings apply to all the lines in the plot. To set the properties of an individual line, retrieve the handle to the line in the geoplot return value h and use dot notation.

The name-value pairs listed here are only a subset. For a full list, see Line Properties.

Line color, specified as 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 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. Thus, 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'

Line style, specified as one of the options listed in this table.

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

'none'No lineNo line

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 symbol, specified as one of the markers in this table. By default, a chart line does not have markers. Add markers at each data point along the line by specifying a marker symbol.

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

's'Square

Sample of square marker

'd'Diamond

Sample of diamond line 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

'p'Pentagram

Sample of pentagram marker

'h'Hexagram

Sample of hexagram marker

'none'No markersNot applicable

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 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. Thus, 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 size, specified as a positive value in points, where 1 point = 1/72 of an inch.

Output Arguments

collapse all

Geographic plot, returned as a column vector of Line objects. Each object corresponds to a plotted line. Use h to modify the properties of the objects after they are created.

Tips

  • Plot 3-D geographic data using the Mapping Toolbox™ functions geoglobe (Mapping Toolbox) and geoplot3 (Mapping Toolbox).

  • To customize certain aspects of your plot, use properties of the geographic axes. For a list of properties, see GeographicAxes Properties.

  • To plot additional data in the geographic axes, use the hold on command.

  • You cannot plot data that requires Cartesian axes in a geographic axes.

  • When you plot on geographic axes, the geoplot function assumes that coordinates are referenced to the WGS84 coordinate reference system. If you plot using coordinates that are referenced to a different coordinate reference system, then the coordinates may appear misaligned.

Introduced in R2018b

[1] Alignment of boundaries and region labels are a presentation of the feature provided by the data vendors and do not imply endorsement by MathWorks®.