地图的主要和次要刻度?

cod*_*tor 9 matlab plot gridlines geo matlab-figure

我创建了下面的地图,它有一个均匀的灰色网格,间隔为1°,对于经线和纬线:

用灰色网格映射

我还希望每隔5°间隔(同时保持1°网格)使经线和平行线变粗和变黑,以便网格线与纬度和经度标签匹配,如下所示:

地图与灰色和黑色网格

我知道MATLAB有标准2D图的主要和次要网格,我过去曾使用它们.但是,据我所知,地图没有此功能.

我认为我想要做的就是通过访问地图对象属性(使用gcmgetm)并为特定子午线和平行子(使用)指定黑色属性来实现setm.也许功能gridmaxesm可以处理这个,但我不确定.

在实践中,我不知道如何做到这一点,因为我没有任何地图经验.我真的很感激你的帮助.

码:

注意:此代码需要Mapping Toolbox.

% Read vector features and attributes from shapefile.
landareas = shaperead('landareas.shp', 'UseGeoCoords', true);

% Define map axes and set map properties.
axesm ('lambert',...
    'MapLonLimit', [-70 10],...
    'MapLatLimit', [30 70],...
    'MapParallels', [38.00555556 71.01111111],...
    'Frame', 'on',...
    'FLineWidth', 1,...
    'Grid', 'on',...
    'GLineStyle', '-',...
    'GLineWidth', 0.1,...
    'GColor', [.7 .7 .7]);

% Display map latitude and longitude data.
geoshow(landareas, 'FaceColor', [1 1 .5], 'EdgeColor', [.3 .3 .3]);

% Toggle and control display of graticule lines.
gridm('MLineLocation', 1,...
    'MLabelLocation', 5,...
    'PLineLocation', 1,...
    'PLabelLocation', 5);

% Toggle and control display of meridian labels.
mlabel on;

% Toggle and control display of parallel labels.
plabel on;

axis off;
Run Code Online (Sandbox Code Playgroud)

erf*_*fan 7

这是一个非常简单的技巧:axes在同一个中制作第二个并在'Position'那里制作所需的主要网格.

从一些修改(我结合你的代码开始axesmgridm):

landareas = shaperead('landareas.shp', 'UseGeoCoords', true);

% make the first axes and get the handle of it
ha = axes;

axesm ('lambert',...
    'MapLonLimit', [-70 10],...
    'MapLatLimit', [30 70],...
    'MapParallels', [38.00555556 71.01111111],...
    'Grid', 'on',...
    'GLineStyle', '-',...
    'GLineWidth', 0.1,...
    'GColor', [.7 .7 .7], ...
    'MLineLocation', 1,...
    'PLineLocation', 1);

geoshow(landareas, 'FaceColor', [1 1 .5], 'EdgeColor', [.3 .3 .3]);

axis off;
Run Code Online (Sandbox Code Playgroud)

然后制作第二个轴:

% get the position of the first axes
L = get(ha, 'Position');

% make a new axes in the same position
axes('Position', L)

axesm ('lambert',...
    'MapLonLimit', [-70 10],...
    'MapLatLimit', [30 70],...
    'MapParallels', [38.00555556 71.01111111],...
    'Frame', 'on',...
    'FLineWidth', 2,...
    'Grid', 'on',...
    'GLineStyle', '-',...
    'GLineWidth', 2,...
    'GColor', [.2 .2 .2], ...
    'MLineLocation', 5,...
    'MLabelLocation', 5,...
    'PLineLocation', 5,...
    'PLabelLocation', 5);

mlabel on;
plabel on;
axis off;
Run Code Online (Sandbox Code Playgroud)

你会得到这个结果:

在此输入图像描述

甚至不需要获取和设置位置,因为它们都将在默认位置创建.


Dev*_*-iL 6

TL; DR

使用这个稍微修改过的代码版本:

% Read vector features and attributes from shapefile.
landareas = shaperead('landareas.shp', 'UseGeoCoords', true);

% Define map axes and set map properties.
hAx = axesm ('lambert',...  <<<<<<<<<<<<<<<<<<<<<<<<< Change #1
    'MapLonLimit', [-70 10],...
    'MapLatLimit', [30 70],...
    'MapParallels', [38.00555556 71.01111111],...
    'Frame', 'on',...
    'FLineWidth', 1,...
    'Grid', 'on',...
    'GLineStyle', '-',...
    'GLineWidth', 0.1,...
    'GColor', [.7 .7 .7]);

% Display map latitude and longitude data.
geoshow(landareas, 'FaceColor', [1 1 .5], 'EdgeColor', [.3 .3 .3]);

% Toggle and control display of graticule lines.
hGrid = gridm(... <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Change #2
  'MLineLocation', 1,... 
  'PLineLocation', 1);

% Change #3:
hGridCopy = copyobj(hGrid,hAx); 
set(hGridCopy,'Tag','oldGrid');  % We use this to hide the grid from handlem,
gridm(...                          so that it doesn't get found and deleted.
  'MLineLocation', 5,...
  'MLabelLocation', 5,...
  'PLineLocation', 5,...
  'PLabelLocation', 5,...
  'GColor',[0,0,0],...
  'GLineWidth',3);

% Toggle and control display of meridian labels.
mlabel on;

% Toggle and control display of parallel labels.
plabel on;

axis off;
Run Code Online (Sandbox Code Playgroud)

要了解这个hacky解决方案的来源,请参阅下面的部分.


当看到生成的句柄时axesm,我们可以了解一下地图的结构:

% Change from this:
axesm ('lambert',...
% To this:
hAx = axesm ('lambert',...
Run Code Online (Sandbox Code Playgroud)

然后,hAx.Children给我们以下内容:

ans = 

  30×1 graphics array:

  Text     (PLabel)
  ... 
  Text     (MLabel)
  Line     (Parallel)
  Line     (Meridian)
  Group
  Patch    (Frame)
Run Code Online (Sandbox Code Playgroud)

由此我们得知的行,即每个集合MeridianParallel,实际上是在一个单一的对象,这意味着某种类型的所有行必须有相同的风格-不像"传统"的未成年人主要 grid线路(可以不同).如果我们想要一些行不同,我们必须创建一个具有所需属性的新对象(行的子集).

现在,创建这些极地网格线的最简单方法是gridm再次调用,但是,这会删除已经绘制的所有网格.它是如何做到的?gridm内部调用handlem('grid'),查找具有Tag任何一个的图形对象,Parallel或者Meridian,找到的对象稍后被删除并替换为具有新外观的对象.那么我们该怎么办?当然,我们"隐藏"网格handlem(参见Change #3;通过更改Tag这些对象的属性)!然后我们只创建另一个网格,我们就完成了.