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". Display the land areas in a neutral color by setting the SeriesIndex property to "none".

land = readgeotable("landareas.shp");
subland = land([1:2,5:18,20:end],:);
geoplot(subland,HandleVisibility="off",SeriesIndex="none",FaceAlpha=0.2)

Display world rivers using lines.

rivers = readgeotable("worldrivers.shp");
geoplot(rivers)

Display the locations of tsunamis events using points. Prepare to add data tips to the points by returning the Point object as pt.

tsunamis = readgeotable("tsunamis.shp",CoordinateSystemType="geographic");
pt = geoplot(tsunamis,MarkerSize=18);

Adjust the geographic limits.

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

Figure contains an axes object with type mapaxes. The mapaxes object contains 2 objects of type line, point.

Add Title

Add a title using the title function.

title("Map of Southeast Asia")

Figure contains an axes object with type mapaxes. The mapaxes object contains 2 objects of type line, point.

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")

Figure contains an axes object with type mapaxes. The mapaxes object contains 2 objects of type line, point. These objects represent Rivers, Tsunami Events.

Change Font Size

Change the font size by using the fontsize function. The fontsize function affects the sizes of fonts used in the title, tick labels, and scale bar, as well as any legends or color bars associated with the axes.

fontsize(12,"points")

Figure contains an axes object with type mapaxes. The mapaxes object contains 2 objects of type line, point. These objects represent Rivers, Tsunami Events.

To change the font size of only the title, access the title of the current MapAxes object. Then, set the FontSize property of the title.

mx = gca;
mx.Title.FontSize = 10;

Figure contains an axes object with type mapaxes. The mapaxes object contains 2 objects of type line, point. These objects represent Rivers, Tsunami Events.

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")

Figure contains an axes object with type mapaxes. The mapaxes object contains 3 objects of type line, point, text. These objects represent Rivers, Tsunami Events.

Add Data Tips

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

dt = datatip(pt,-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 Add Data Tips to Point, Line, and Polygon Shapes.

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

Figure contains an axes object with type mapaxes. The mapaxes object contains 3 objects of type line, point, text. These objects represent Rivers, Tsunami Events.

See Also

Functions

Properties

Topics