主要内容

本页采用了机器翻译。点击此处可查看英文原文。

在地图坐标区上添加标签和注解

地图坐标轴对象是一种坐标轴对象,与坐标轴对象、地理坐标区对象和极坐标轴对象类似。因此,您可以将坐标轴与许多 MATLAB® 图形函数结合使用。本示例演示了如何通过添加标题、图例、文本和数据提示来传达地图信息。

默认情况下,大多数绘图函数会重置许多坐标轴属性。此示例通过将坐标轴的保持状态设置为 on,保留了坐标轴中的图和自定义设置。或者,您也可以在绘图后自定义坐标轴。

创建地图

使用适合东南亚的投影坐标系绘制一张地图。使用 ESRI 代码 102030 创建 projcrs 对象。

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

通过显示包含世界陆地面积的 shapefile 子集,为地图提供地理背景。将 HandleVisibility 属性设置为 "off",即可避免在图例中显示陆地区域。将 SeriesIndex 属性设置为 "none",以中性颜色显示陆地区域。

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

用线条显示世界上的河流。

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

使用点来显示海啸事件的发生地点。将 Point 对象作为 pt 返回,以便为数据点添加数据提示。

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

调整地理范围。

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

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

添加标题

使用 title 函数添加标题。

title("Map of Southeast Asia")

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

添加图例

为折线图和散点图添加包含说明的图例。将图例标签指定为 legend 函数的输入。有关在坐标轴上添加图例的信息,请参阅 将图例添加到图

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.

更改字体大小

使用 fontsize 函数更改字体大小。fontsize 函数会影响标题、刻度标签和比例尺中使用的字体大小,以及与坐标轴相关的任何图例或颜色栏的字体大小。

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.

若要仅更改标题的字体大小,请访问当前 MapAxes 对象的标题。然后,设置标题的 FontSize 属性。

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.

添加文本

在地图上添加文字。使用经纬度坐标指定文本的位置。有关在坐标轴上添加文本的信息,请参阅 向图中添加文本

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.

添加数据提示

通过添加数据提示,显示海啸事件的坐标。将 Point 对象和经纬度坐标作为输入传递给 datatip 函数。

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

通过在数据提示模板中添加新行,在数据提示中显示海啸事件的原因。有关自定义数据提示的更多信息,请参阅 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.

另请参阅

函数

属性

主题