Main Content

Display Vector Data as Lines and Patches

Display vector data on maps as lines and patches (filled polygons).

This page shows how to create similar maps using map axes (since R2023a) and axesm-based maps. For a comparison of map axes and axesm-based maps, including when to use each type of display, see Choose a 2-D Map Display.

Prepare Data

Prepare the data to use in the examples.

Load a MAT file containing the latitude and longitude coordinates of several polygons and lines. The data separates individual polygons and lines using NaN values.

  • uslat and uslon — Polygons representing the conterminous United States.

  • gtlakelat and gtlakelon — Polygons representing the Great Lakes.

  • statelat and statelon — Lines representing the borders between states.

load conus

Use the data to create polygon and line shapes. Combine the shapes into a geospatial table.

us = geopolyshape(uslat,uslon);
gtlake = geopolyshape(gtlakelat,gtlakelon);
states = geolineshape(statelat,statelon);
conusGT = table([us; gtlake; states],VariableNames="Shape")
conusGT=3×1 table


Read a shapefile containing world rivers into a geospatial table. The table represents the rivers using line shapes in geographic coordinates. Clip the line shapes to a region that covers the conterminous United States.

riversGT = readgeotable("worldrivers.shp");

uslatlim = [min(uslat) max(uslat)];
uslonlim = [min(uslon) max(uslon)];
clipped = geoclip(riversGT.Shape,uslatlim,uslonlim);
riversGT.Shape = clipped;

Create Map Using Map Axes

Display vector data on a map axes object as lines and polygons.

Set up a map using a projected coordinate reference system (CRS) that is appropriate for the conterminous United States. Create the projected CRS using the ESRI code 102003.

proj = projcrs(102003,Authority="ESRI");
hold on

Display the data on the map by using the geoplot function.

  • Display the conterminous United States using green polygons.

  • Display the Great Lakes using opaque, light blue polygons.

  • Display the state boundaries using black lines.

  • Display the rivers using blue lines.

geoplot(conusGT(1,:),FaceColor=[0.4660 0.6740 0.1880])
geoplot(conusGT(2,:),FaceAlpha=1,FaceColor=[0.3010 0.7450 0.9330])
geoplot(riversGT,Color=[0 0.4470 0.7410])

Create Map Using axesm-Based Maps

Display vector data on an axesm-based map as lines and patches.

Set up an axesm-based map to display the state coordinates, turning on the map frame, map grid, and the meridian and parallel labels. Create the map using an Albers Equal Area Conic projection. Specifying map limits that contain the region of interest automatically centers the projection on an appropriate longitude. The frame encloses just the mapping area, not the entire globe. As a general rule, you should specify map limits that extend slightly outside your area of interest (worldmap and usamap do this for you). Conic projections need two standard parallels (latitudes at which scale distortion is zero). A good rule is to set the standard parallels at one-sixth of the way from both latitude extremes. Or, to use default latitudes for the standard parallels, simply provide an empty matrix in the call to axesm .

axesm("MapProjection","eqaconic","MapParallels",[], ...
      "MapLatLimit",uslatlim + [-2 2], ...
      "MapLonLimit",uslonlim + [-2 2])
axis off 

Display the data on the map by using the geoshow function.

  • Display the conterminous United States using green patches.

  • Display the Great Lakes using light blue patches.

  • Display the state boundaries using black lines.

  • Display the rivers using blue lines.

geoshow(conusGT(1,:),"FaceColor",[0.8157 0.8863 0.7176])
geoshow(conusGT(2,:),"FaceColor",[0.3010 0.7450 0.9330])
geoshow(riversGT,"Color",[0 0.4470 0.7410])


To plot data that is already in projected coordinates, use a regular axes object and the mapshow function.

See Also



Related Topics