| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Mapping Toolbox |
| Contents | Index |
| Learn more about Mapping Toolbox |
| On this page… |
|---|
Mapping Toolbox functions axesm and setm enable you to control the full range of properties when constructing a projected map axes. Functions worldmap and usamap, on the other hand, trade control for simplicity and convenience. These two functions each create a map axes object that is suitable for a country or region of the world or the United States, automatically selecting the map projection, limits, and other properties based on the name of the area you want to map. Once you have jump-started your map with worldmap or usamap, you are ready to add your data, using geoshow or any of the lower level geographic data display functions. Optionally, you can use the map axes object created by worldmap or usamap as a starting point, and then customize it by adjusting selected properties with setm.
The default color for MATLAB figures is gray. If you prefer that your maps have white backgrounds instead, you can create figures with the command
figure('Color','white')If you want a custom background color, specify a color triplet in place of white. For example, to make a beige background, type
figure('Color',[.95 .9 .8])To give a white background to an existing figure, type
set(gca,'color','white')
If you want all figures in a session to have white backgrounds, set this as a default with the command
set(0, 'DefaultFigureColor', 'white');
To avoid having to do this every time you start MATLAB, place this command in your startup.m file.
You can also use the Property Editor, part of the MATLAB plotting tools, to modify background colors for figures and axes. See Plotting Tools — Interactive Plotting in the MATLAB Graphics documentation for more information.
Here are two examples that create simple maps using sample data sets from matlabroot/toolbox/map/mapdemos. The first one creates a map of South America with land areas, major lakes and rivers, and populated places.
First, set up the map frame, allowing worldmap to pick a projection:
figure worldmap 'south america' axis off

You can find out what map projection worldmap selected this way:
getm(gca,'MapProjection') ans = eqdconic
This denotes the Equidistant Conic Projection, which is appropriate for regions in middle latitudes that are elongated along the polar axis.
Next, use geoshow to import data for land areas, major rivers, and major cities from shapefiles and display it using colors you specify:
geoshow('landareas.shp', 'FaceColor', [0.5 0.7 0.5])
geoshow('worldrivers.shp', 'Color', 'blue')
geoshow('worldcities.shp', 'Marker', '.', 'Color', 'red')The map now looks like this.

The usamap function allows you to 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 easiest way to use it is to type
usamap
at the MATLAB prompt. This opens a GUI with a list box from which you can select the entire U.S., the conterminous states, or an individual state to map. The map axes you create with usamap 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 geoshow.
This example creates a map of the Chesapeake Bay region by specifying geographic limits.
First, specify limits and set up a map axes object:
latlim = [ 37 40]; lonlim = [-78 -74]; figure ax = usamap(latlim,lonlim); axis off

The Lambert Conformal Conic Projection is often used for maps of the conterminous United States.
Here is the map projection usamap selected:
getm(gca,'MapProjection') ans = lambert
Next, use shaperead to read U.S. state polygon boundaries from the usastatehi demo shapefile into a geostruct named states:
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 geoshow:
geoshow(ax, states, 'SymbolSpec', faceColors)
Extract the names for states within the window from the geostruct and use textm to plot them at the label points provided by the geostruct:
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)

Note that as polcmap assigns random pastel colors to patches, your map might display different colors than this example. For further information on options for these functions, see the reference pages for geoshow, shaperead, worldmap, and usamap.
![]() | Introduction to Mapping Graphics | Axes for Drawing Maps | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |