Main Content

Add Labels and Annotations to Map Axes

Map axes objects are a type of axes object, similar to axes objects, geographic axes objects, and polar axes objects. As a result, you can use map axes with many MATLAB® graphics functions. This example shows how to convey information about your map by adding a title, a legend, text, and data tips.

By default, most plotting functions reset many of the axes properties. This example retains the plots and customizations in the axes by setting the hold state of the axes to on. Alternatively, you can customize the axes after plotting.

Create Map

Create a map using a projected CRS that is appropriate for Southeast Asia. Create the projcrs object using the ESRI code 102030.

figure
p = projcrs(102030,Authority="ESRI");
newmap(p)
hold on

Provide geographic context for the map by displaying a subset of a shapefile containing world land areas. Avoid displaying 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])

Display world rivers using blue lines.

rivers = readgeotable("worldrivers.shp");
geoplot(rivers,Color=[0 0.4470 0.7410])

Display the locations of tsunamis events using a scatter chart. Prepare to add data tips to the scatter chart by returning the Scatter object as s.

tsunamis = readgeotable("tsunamis.shp",CoordinateSystemType="geographic");
lat = tsunamis.Shape.Latitude;
lon = tsunamis.Shape.Longitude;
s = geoscatter(lat,lon,"filled",MarkerFaceColor=[0.8500 0.3250 0.0980]);

Adjust the geographic limits.

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

Add Title

Add a title using the title function.

title("Map of Southeast Asia")

Add Legend

Add a legend with descriptions for the lines and scatter chart. Specify the legend labels as inputs to the legend function. For more information about adding legends to axes, see Add Legend to Graph.

legend(["Rivers", "Tsunami Events"],Location="northeast")

Change Font Size

MapAxes objects have properties that you can use to customize the appearance of the axes. For example, the FontSize property controls the font size of the title, tick labels, and scale bar, as well as any legends or color bars associated with the axes.

Access the current MapAxes object and then set the FontSize property.

mx = gca;
mx.FontSize = 12;

To change the font size of only the title, set the FontSize property of the title.

mx.Title.FontSize = 10;

Add Text

Add text to the map. Specify the location for the text using latitude-longitude coordinates. For more information about adding text to axes, see Add Text to Chart.

text(10.2,126.5,"Philippines")

Add Data Tips

Display the coordinates of a tsunami event by adding a data tip. Specify the scatter chart and latitude-longitude coordinates as inputs to the datatip function.

dt = datatip(s,-11.1,118.4,Location="southeast");

Display the cause of the tsunami event in the data tip by adding a new row to the data tip template. For more information about customizing data tips, see Create Custom Data Tips.

dtRow = dataTipTextRow("Cause",tsunamis.Cause);
s.DataTipTemplate.DataTipRows(end+1) = dtRow;

See Also

Functions

Properties

Related Topics