Open Live Script
(Since R2023a)
Map axes objects are a type of axes object, similar to axes objects, geographic axes objects, and polar axes objects. Map axes support several types of plots, including point, line, and polygon plots (geoplot
), scatter plots (geoscatter
), bubble charts (bubblechart
), and comet plots (comet
). You can use map axes with many MATLAB graphics functions, including gca
, hold
, geolimits
, title
, and legend
.
Create Map Axes
Unlike other types of axes, map axes require you to create the map axes object before plotting data into it. You can create a map axes object by using the newmap
or mapaxes
function.
Use newmap when you want to create a map in the default projection or in a specified projection.
Use mapaxes when you want advanced control of the map, or when you want to include the map in an app.
Create Point, Line, and Polygon Plots
Display points, lines, and polygons on map axes by using the geoplot function. You can specify geospatial tables, shape objects, or numeric coordinates as input to the geoplot
function. When you specify geospatial tables or shape objects, you can plot data in any supported geographic or projected coordinate reference system (CRS).
Set up a new map. By default, map axes use an Equal Earth map projection.
figurenewmap
Read three shapefiles into the workspace. The files contain world land areas, rivers and cities. Then, display the land areas as green polygons, the rivers as blue lines, and the city locations as black points.
land = readgeotable("landareas.shp");rivers = readgeotable("worldrivers.shp");cities = readgeotable("worldcities.shp");geoplot(land,FaceColor=[0.7 0.9 0.5],EdgeColor="none")hold ongeoplot(rivers,Color=[0 0.4470 0.7410])geoplot(cities,"k")
Add a title.
title("World Land Areas, Rivers, and Cities")
Create Scatter Plots
Display scatter plots on map axes by using the geoscatter function. To use the geoscatter
function with map axes, you must specify the coordinates using numeric latitudes and longitudes.
Set up a new map using a projected CRS that is appropriate for Europe. For this example, create the CRS using the EPSG code 3035
, which uses a Lambert Azimuthal Equal Area projection method.
figurep = projcrs(3035);newmap(p)
Read a shapefile containing world land areas into the workspace. Provide geographic context for the map by displaying the land areas.
land = readgeotable("landareas.shp");geoplot(land,FaceColor=[0.7 0.7 0.7],EdgeColor=[0.65 0.65 0.65])hold on
Read a shapefile containing the locations of world cities into the workspace. Extract the numeric latitude and longitude coordinates. Then, display the city locations using a scatter plot.
cities = readgeotable("worldcities.shp");lat = cities.Shape.Latitude;lon = cities.Shape.Longitude;geoscatter(lat,lon,"filled")
Adjust the geographic limits. Then, add a title and subtitle.
geolimits([35 72],[-25 45])title("Map of Europe")subtitle(p.ProjectionMethod)
Create Bubble Charts
Display bubble charts on map axes by using the bubblechart function. To use the bubblechart
function with map axes, you must specify the coordinates using numeric latitudes and longitudes.
Load Data
Load into the workspace a shapefile containing tsunami events, including attributes such as the maximum heights and the causes. Extract the latitudes, longitudes, maximum heights, and causes. Replace missing causes with "Unknown Cause"
.
tsunamis = readgeotable("tsunamis.shp",CoordinateSystemType="geographic");lat = tsunamis.Shape.Latitude;lon = tsunamis.Shape.Longitude;maxheight = tsunamis.Max_Height;c = categorical(tsunamis.Cause);c = fillmissing(c,"constant","Unknown Cause");
Set Up Map
This example adds multiple legends to the bubble chart. To manage the alignment of the legends, use a tiled chart layout.
figuret = tiledlayout(1,1);nexttile
Set up a new map using a projected CRS that is appropriate for Southeast Asia. For this example, create a CRS using the ESRI code 102030
, which uses a Lambert Conic Conformal projection method.
p = projcrs(102030,Authority="ESRI");newmap(p)
Read a shapefile containing world land areas into the workspace. Provide geographic context for the map by displaying a subset of the land areas. Avoid including the land areas in the legend by setting the HandleVisibility
property to "off"
.
land = readgeotable("landareas.shp");subland = land([1:2,5:18,20:end],:);geoplot(subland,HandleVisibility="off",FaceColor=[0.7 0.7 0.7],EdgeColor=[0.65 0.65 0.65])hold on
Plot Data
Display the data using a bubble chart. To create a legend that illustrates the tsunami causes, use a separate bubble chart for each cause. Specify the bubble sizes using the maximum heights.
causes = categories(c);numCauses = length(causes);mx = gca; for k = 1:numCauses cause = causes(k); idx = c == cause; bubblechart(mx,lat(idx),lon(idx),maxheight(idx),DisplayName=string(cause))end
Note that, to use the bubblechart
function with map axes, you must specify the map axes as the target.
Customize Plot
Customize the plot by changing the bubble sizes, adding legends, changing the geographic limits, and adding a subtitle and title.
Specify the minimum and maximum bubble sizes (in points).
bubblesize([3 30])
Add two legends. Illustrate the bubble colors using a legend, and illustrate the bubble sizes using a bubble legend. Store each legend object by specifying an output argument for the bubblelegend
and legend
functions. Then, move the legends to the bottom outer tile of the tiled chart layout by setting the Layout.Tile
property on each object to "south"
.
lgd = legend;title(lgd,"Cause")blgd = bubblelegend("Maximum Height (m)");lgd.Layout.Tile = "south";blgd.Layout.Tile = "south";
Change the bubble size limits to reflect the sizes of bubbles in Southeast Asia.
bubblelim([1 50])
Adjust the geographic limits.
geolimits([-20 20],[90 170])
Add a title and subtitle.
title("Tsunamis by Cause and Maximum Height")subtitle(p.ProjectionMethod)
See Also
Functions
- newmap | geoplot | geoscatter | bubblechart
Properties
- MapAxes Properties
Related Topics
- Customize Appearance of Map Axes
- Change Projection and Projection Parameters
- Create Geospatial Tables
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office