Inset Maps
An inset map is a smaller map displayed inside a larger map. You can use an inset map to create geographic context for the larger map. This example shows how to create a map of Massachusetts and include an inset map of the northeastern United States.
This example shows how to create an inset map in an axesm
-based map. For an example of creating inset maps in map axes (since R2023a), see Position Multiple Map Axes in Figure on the mapaxes
reference page. 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
Read USA state boundaries from a shapefile. Indicate that file contains latitude and longitude coordinates by specifying the UseGeoCoords
name-value argument.
states = shaperead('usastatehi.shp','UseGeoCoords',true);
Extract the state boundaries of Massachusetts and find their latitude and longitude limits.
ma = states(strcmp({states.Name},'Massachusetts'));
latlim = [min(ma.Lat) max(ma.Lat)];
lonlim = [min(ma.Lon) max(ma.Lon)];
Create Map
Create a map using the latitude and longitude coordinates. Set the face frame color of the map to light blue. Display the USA boundaries as light-brown polygons and the Massachusetts boundaries as green polygons.
figure h1 = usamap(latlim,lonlim); setm(h1,'FFaceColor','#B7E9F7') geoshow(states,'FaceColor','#EFE6DC') geoshow(ma,'FaceColor','#90EE90')
Create Inset Map
Create an inset map. To do this, first create axes in the lower-left of the map frame. Place a map with latitude and longitude limits that contain Pennsylvania and Maine inside the axes, remove the parallel and meridian labels, and remove the grid lines. Then, display the USA boundaries as gray polygons and the Massachusetts boundaries as green polygons.
h2 = axes('Position',[0.15 0.25 0.2 0.2]); usamap({'PA','ME'}) setm(h2,'FFaceColor','w') plabel off mlabel off gridm off geoshow(states,'FaceColor','#EDEDED') geoshow(ma,'FaceColor','#90EE90')