Main Content

Create Simple Maps Using usamap

This example shows how to create axesm-based maps of the United States by using the usamap function. The usamap function lets you make maps of the United States as a whole, just the conterminous portion (the "lower 48" states), groups of states, or a single state. The map you create with the usamap function has a labelled grid fitted around the area you specify but contains no data, allowing you to generate the kind of map you want using display functions such as the geoshow function.

Specify map limits and set up an axesm-based map. This example creates a map of the Chesapeake Bay region.

latlim = [37 40];
lonlim = [-78 -74];
ax = usamap(latlim,lonlim);
axis off

Determine the map projection used by the usamap function. The Lambert Conformal Conic projection is often used for maps of the conterminous United States.

ans = 

Use the readgeotable function to read U.S. state polygon boundaries from the shapefile called usastatehi.shp. The function returns the data in a geospatial table.

states = readgeotable('usastatehi.shp');

Create a symbol specification to create a political map using the polcmap function.

h = height(states);
faceColors = makesymbolspec('Polygon',...
    {'INDEX',[1 h],'FaceColor',polcmap(h)});

Display the filled polygons by using the geoshow function.


Extract the names for states within the map limits and use the textm function to plot them at the label points provided by the geospatial table. Because polcmap assigns random pastel colors to patches, your map might look different than this example.

for k = 1:h
    labelPointIsWithinLimits = ...
        latlim(1) < states.LabelLat(k) &&...
        latlim(2) > states.LabelLat(k) &&...
        lonlim(1) < states.LabelLon(k) &&...
        lonlim(2) > states.LabelLon(k);
    if labelPointIsWithinLimits
            states.LabelLon(k), states.Name(k),...
textm(38.2,-76.1,' Chesapeake Bay ',...