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 file contains the following variables. Note that the data separates individual polygons and lines using NaN values.
uslatanduslon— Polygons representing the conterminous United States.gtlakelatandgtlakelon— Polygons representing the Great Lakes.statelatandstatelon— Lines representing the borders between states.
load conus.matUse the data to create polygon and line shapes.
us = geopolyshape(uslat,uslon); gtlake = geopolyshape(gtlakelat,gtlakelon); states = geolineshape(statelat,statelon);
Read a shapefile containing world rivers into a geospatial table. The table represents the rivers using line shapes in geographic coordinates.
riversGT = readgeotable("worldrivers.shp");Clip the line shapes in the geospatial table to the polygon shape that represents the conterminous United States.
clipped = geoclip(riversGT.Shape,us); riversGT.Shape = clipped;
Create Map Using Map Axes
Display vector data on a map axes object using 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.
figure proj = projcrs(102003,Authority="ESRI"); newmap(proj) 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(us,FaceColor=[0.4660 0.6740 0.1880])
geoplot(gtlake,FaceAlpha=1,FaceColor=[0.3010 0.7450 0.9330])
geoplot(states,Color="k")
geoplot(riversGT,Color=[0 0.4470 0.7410])
Create Map Using axesm-Based Map
Display vector data on an axesm-based map using lines and patches.
Create a polygon shape that extends outside of the conterminous United States by using the buffer function. Then, calculate the latitude and longitude limits to use for the axesm-based map by using the bounds function.
buffered = buffer(us,2); [latlim,lonlim] = bounds(buffered);
Create an axesm-based map by using the axesm function, an Equal Area Conic projection, and the calculated limits. When you specify map limits, the map automatically centers the projection on an appropriate longitude. Use the default latitudes for the standard parallels by specifying the MapParallels argument as an empty matrix.
figure axesm(MapProjection="eqaconic",MapParallels=[], ... MapLatLimit=latlim,MapLonLimit=lonlim) axis off
Display the map frame, map grid, meridian labels, and parallel labels.
framem gridm mlabel plabel
Collect the shape objects into a geospatial table. Then, 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.
conusGT = table([us; gtlake; states],VariableNames="Shape"); geoshow(conusGT(1,:),FaceColor=[0.8157 0.8863 0.7176]) geoshow(conusGT(2,:),FaceColor=[0.3010 0.7450 0.9330]) geoshow(conusGT(3,:),Color="k") geoshow(riversGT,Color=[0 0.4470 0.7410])

Tips
Unlike the
axesmfunction, theworldmapandusamapfunctions automatically select appropriate limits based on the input data.To plot data that is already in projected coordinates, use a regular axes object and the
mapshowfunction.