Main Content

Create Simple Maps Using usamap

This example shows how to create maps of the United States 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 axes 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 a map axes object. This example creates a map of the Chesapeake Bay region.

latlim = [37 40];
lonlim = [-78 -74];
figure
ax = usamap(latlim, lonlim)
ax = 
  Axes with properties:

             XLim: [-1.8118e+05 1.8118e+05]
             YLim: [4.4299e+06 4.7720e+06]
           XScale: 'linear'
           YScale: 'linear'
    GridLineStyle: '-'
         Position: [0.1300 0.1100 0.7750 0.8150]
            Units: 'normalized'

  Show all properties

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.

getm(gca,'MapProjection')
ans = 
'lambert'

Use the shaperead function to read U.S. state polygon boundaries from the usastatehi shapefile. The function returns the data in a geostruct.

states = shaperead('usastatehi',...
    'UseGeoCoords',true,'BoundingBox',[lonlim',latlim']);

Make a symbolspec to create a political map using the polcmap function.

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

Display the filled polygons with the geoshow function.

geoshow(ax,states,'SymbolSpec',faceColors)

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

for k = 1:numel(states)
    labelPointIsWithinLimits = ...
        latlim(1) < states(k).LabelLat &&...
        latlim(2) > states(k).LabelLat &&...
        lonlim(1) < states(k).LabelLon &&...
        lonlim(2) > states(k).LabelLon;
    if labelPointIsWithinLimits
        textm(states(k).LabelLat,...
            states(k).LabelLon, states(k).Name,...
            'HorizontalAlignment','center')
    end
end
textm(38.2,-76.1,' Chesapeake Bay ',...
    'fontweight','bold','Rotation',270)