Create Common Plots Using Map Axes

(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.

```figure newmap```

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 on geoplot(rivers,Color=[0 0.4470 0.7410]) geoplot(cities,"k")```

`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.

```figure p = 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")```

```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 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.

```figure t = 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])`

`geolimits([-20 20],[90 170])`

```title("Tsunamis by Cause and Maximum Height") subtitle(p.ProjectionMethod)```