Matlab下地形图绘图包m_map绘图之添加线段比例尺函数m_ruler

1. 前言

之前已经写了:

Matlab下地形图绘图包m_map安装与使用
m_map绘制晕渲(shaded relief)地形图
m_map绘图包绘制高分辨率海岸线、国界线与河流

现在再介绍一下比例尺函数m_ruler,这个是线段比例尺。
对于小范围的地形图是适用的,当绘图范围为全球时不太适用。

2. 函数说明

打开matlab,命令行输入help m_ruler查看用法

>> help m_ruler
  m_ruler Draws a distance scalebar for a map
    m_ruler([X1 X2],Y1) draws a horizontal scale bar between the
    normalized coordinates (X1,Y1) and (X2,Y1) where both X/Y are
    in the range 0 to 1.  
    m_ruler(X1,[Y1 Y2]) draws a vertical scalebar
    m_ruler(...,NINTS) draws the scalebar with NINTS intervals
    if NINTS is a scalar (default 4).  Distances of each interval are 
    chosen to be 'nice'. If NINTS is a vector it is understood to be
    the distances to be used (in meters)
 
    m_ruler(....,'parameter','value',...) lets you specify
    extra parameter/value pairs in the usual handle-graphics way.
    'color' and 'fontsize' are probably the most useful, 'tickdir'
    'in' and 'out' chooses between different styles.
 
    Probably BEST to call this AFTER M_GRID otherwise placement might
    seem a bit odd.
 
  WARNING - the scalebar is probably not useful for any global
            (i.e. whole-world) or even a significant-part-of-the-globe
            map, but I won't stop you using it. Caveat user!

说明:
m_ruler([X1 X2],Y1)是画水平比例尺,都表示归一化[0,1]的横向宽度与垂向高度。
m_ruler(X1,[Y1 Y2])是画垂向比例尺,都表示归一化[0,1]的横向宽度与垂向高度。
m_ruler(...,NINTS)可以设置线段的分段数。
m_ruler(....,'parameter','value',...)可以设置一些线参数。例如:
'color'表示刻度颜色
'fontsize'表示标签字号
'ticklength'表示刻度线长度
'tickdir'表示比例尺类型,有两种,分别为inout
'tickwidth'表示线框厚度,只适用于'tickdir''out'的情况。

3. 例子

例子在m_map绘图包绘制高分辨率海岸线、国界线与河流基础上进行。

3.1 例1

横向显示,tickdir设为out,线段设为6段。

figname='ruler1';
figure
m_proj('mercator','long',[116 124],'lat',[26 32]);

caxis([-500 2000]) 
% %caxis要放在colormap之前,colormap要放在m_shadedrelief之前
colormap([m_colmap('blue',50);m_colmap('gland',200)])
hc=colorbar('southoutside','fontsize',12);
set(get(hc,'title'),'string','Elevation(m)','fontsize',12)

m_etopo2('shadedrelief','lightangle',45);

m_gshhs('ic','color',[.5 .5 .5])
m_gshhs('hr3','color','b')
m_grid('box','fancy','tickdir','in','gridlines','no',...
    'fontsize',12,'xaxislocation','top')
m_ruler([0.6 0.9],0.1,6,'color','b',...
    'linewid',5,'tickdir','out','ticklen',0.01,'fontsize',10);

set(gcf,'position',[100 100 800 600])
print('-dpng','-r400',[figname,'.png'])

3.2 例2

横向显示,tickdir设为out,线段设为4段。

figname='ruler2';
figure
m_proj('mercator','long',[116 124],'lat',[26 32]);

caxis([-500 2000]) 
% %caxis要放在colormap之前,colormap要放在m_shadedrelief之前
colormap([m_colmap('blue',50);m_colmap('gland',200)])
hc=colorbar('southoutside','fontsize',12);
set(get(hc,'title'),'string','Elevation(m)','fontsize',12)

m_etopo2('shadedrelief','lightangle',45);

m_gshhs('ic','color',[.5 .5 .5])
m_gshhs('hr3','color','b')
m_grid('box','fancy','tickdir','in','gridlines','no',...
    'fontsize',12,'xaxislocation','top')
m_ruler([0.6 0.9],0.1,4,'color','b',...
    'linewid',5,'tickdir','out','ticklen',0.01,'fontsize',10);

set(gcf,'position',[100 100 800 600])
print('-dpng','-r400',[figname,'.png'])

3.3 例3

横向显示,tickdir设为in,线段设为6段。

figname='ruler3';
figure
m_proj('mercator','long',[116 124],'lat',[26 32]);

caxis([-500 2000]) 
% %caxis要放在colormap之前,colormap要放在m_shadedrelief之前
colormap([m_colmap('blue',50);m_colmap('gland',200)])
hc=colorbar('southoutside','fontsize',12);
set(get(hc,'title'),'string','Elevation(m)','fontsize',12)

m_etopo2('shadedrelief','lightangle',45);

m_gshhs('ic','color',[.5 .5 .5])
m_gshhs('hr3','color','b')
m_grid('box','fancy','tickdir','in','gridlines','no',...
    'fontsize',12,'xaxislocation','top')
m_ruler([0.6 0.9],0.1,6,'color','b',...
    'linewid',2,'tickdir','in','ticklen',0.01,'fontsize',10);

set(gcf,'position',[100 100 800 600])
print('-dpng','-r400',[figname,'.png'])

3.4 例4

垂向显示,tickdir设为in,线段设为6段。

figname='ruler4';
figure
m_proj('mercator','long',[116 124],'lat',[26 32]);

caxis([-500 2000]) 
% %caxis要放在colormap之前,colormap要放在m_shadedrelief之前
colormap([m_colmap('blue',50);m_colmap('gland',200)])
hc=colorbar('southoutside','fontsize',12);
set(get(hc,'title'),'string','Elevation(m)','fontsize',12)

m_etopo2('shadedrelief','lightangle',45);

m_gshhs('ic','color',[.5 .5 .5])
m_gshhs('hr3','color','b')
m_grid('box','fancy','tickdir','in','gridlines','no',...
    'fontsize',12,'xaxislocation','top')
m_ruler(1.05,[0.5,0.8],6,'color','k',...
    'linewid',3,'tickdir','in','ticklen',0.01,'fontsize',10);

set(gcf,'position',[100 100 800 600])
print('-dpng','-r400',[figname,'.png'])

END

你可能感兴趣的:(M_Map,Matlab,matlab,可视化,map)