M_Map m_contourf m_shadedrelief m_etopo2实例(caxis colormap)

在用M_Map绘制彩色地形时,可以使用m_contourf m_shadedrelief(阴影浮雕地图) m_etopo2三个函数分别绘图(当然还可以用m_pcolor等函数)。本篇博客的内容是调用etopo地形水深数据库,对**中国南海与其临近海域(东经105-125°,北纬2-24°)**的水深地形作图。作图步骤细节较简略,若想让绘图更美观,则需指定更多的绘图参数。

% m_shadedtelief函数的两种用法
% 方式1 m_etopo2('shadedtelief')
% 方式2 m_shadedtelief(x,y,z,'...')
% 必须先调用caxis与colormap,再m_shadedtelief

% 中国南海与其临近区域 东经105~125°,北纬2~24°

% [ELEV,LON,LAT]=m_etopo2([Lon_Min Lon_Max Lat_Min Lat_Max]) 

[elev,lon,lat]=m_etopo2([105 125 2 24]);
min(elev(:)); % -7318
max(elev(:)); % 3816

% caxis([-300 1210]);  % 注意本例caxis包括陆地与海洋同时填色                  
% colormap([m_colmap('blues',32);m_colmap('gland',128)]);%colormap矩阵拼接比例  
% m_shadedrelief(lon(ilon),lat(ilat),Z');     % ESC8 m_shadedrelief

elev矩阵中一般大于0的部分代表陆地,小于0的部分代表海洋。
在上面M_Map官网 ESC8(8. Shaded Relief from a high-resolution topography (netCDF format)) m_shadedrelief例子中,陆地海洋都填色caxis([-300 1210]); ),那么需要用到的colormapRGB(m×3)矩阵则需是分别适用于陆地与海洋颜色的拼接矩阵,即
colormap([m_colmap(‘blues’,32);m_colmap(‘gland’,128)]);

这显然是根据陆地与海洋的深度比例对colormapRGB(m×3)矩阵进行拼接(深度比例参考官网 ESC8的代码注释),期望陆地与海洋分别用不同的颜色表示,只要陆地与海洋分别用不同的颜色表示,那么可以不用m_gshhs函数再绘制海岸线(因为陆地与海洋的颜色已经划分开了,即在上述colormap矩阵拼接处的颜色,可查看EC7. Lambert Conformal Projection with high-resolution bathymetry of Western Mediterranean)。

想只有海洋填色,则需指定 caxis([-3000 0]); 命令,其让elev中高于0的部分全部呈现colormap矩阵中最高的颜色(可查看M_Map官网EC14 One Ocean Projection的ax4 与ax2ax3的区别,如下图截图)。

本例的空间数据矩阵elev是地形水深数据,而一般的海洋学数据在陆地处的数据值(如海表面温度SST)一般是nan,此时SST与其他的空间数据可以不考虑陆地的数值对绘图的影响。之所以地形水深数据必须要考虑陆地值(如50m等数据),是因为在陆地的经纬度处的矩阵不是nan,若想让陆地海洋都填色,则必须考虑caxis函数在大于0处的取值。

注意本篇博客下面三个例子全部是陆地海洋都填色( caxis([-7000 3500]);
在这里插入图片描述

1. m_contourf(x,y,z)

先使用m_etopo2函数提取指定区域的地形水深数据矩阵elev,再用m_contourf函数输入elev矩阵绘制填充等值线图。思路是将地形水深数据矩阵elev当做一般的空间分布矩阵绘制。(可以先指定caxis colormap,再运行m_contourf;也可以先运行m_contourf,再指定caxis colormap)

%% P01-m_contourf 也可以用m_contour函数
figure('units','centimeters','position',[1 3 29.7 21]);
set(gcf,'GraphicsSmoothing','off','color','w')
m_proj('miller','lat',[2 24],'lon',[105 125]);

caxis([-7000 3500]);
colormap([m_colmap('blues',256);m_colmap('gland',128)]);
%m_shadedrelief(lon(1,:),flipud(lat(:,1)),elev);
[CS,CH] = m_contourf(lon(1,:),lat(:,1),elev,...
[-7000:1000:-1000 -500:100:0 50:50:200 300:100:3900],...
'linestyle','none');
m_grid('box','fancy','grid','none','fontsize',14);
title('m_contourf(x,y,z)','interpreter','none',...
    'fontsize',15,'fontweight','bold')
axb1 = m_contfbar([0.90],[0.2 0.9], elev,[-7000:3500],...
            'axfrac',.02,'endpiece','no','levels','match','edgecolor','none');   % 注:此处m_contfbar函数 DATAS, LEVEL也可设为=CS,CH
axb1.TickLength = [0.01 0.01]; 
export_fig(gcf,'m_contourf(x,y,z).fig');
export_fig(gcf,'m_contourf(x,y,z).jpg','-r500');

在这里插入图片描述

2. m_shadedrelief(x,y,z)

本例展示m_shadedrelief函数直接绘图的效果,思路是将地形水深数据矩阵Z=elev当做一般的空间分布矩阵绘制。注意m_shadedrelief函数调用之前必须先指定caxis与colormap两个选项,m_shadedrelief还有其他可选参数可以指定,在本例不展示。(必须先指定caxis colormap,再运行m_shadedrelief !)此用法详见UG5.3一节的警告!

You should call m_shadedrelief only AFTER calls to colormap and caxis, because these are needed to determine the shading in the true-colour image.

%% P02-m_shadedrelief
figure('units','centimeters','position',[1 3 29.7 21]);
set(gcf,'GraphicsSmoothing','off','color','w')
m_proj('miller','lat',[2 24],'lon',[105 125]);

caxis([-7000 3500]);
colormap([m_colmap('blues',256);m_colmap('gland',128)]);
%m_shadedrelief(lon(1,:),flipud(lat(:,1)),elev);
m_shadedrelief(lon(1,:),lat(:,1),elev);
% [CS,CH] = m_contourf(lon(1,:),lat(:,1),elev,...
% [-7000:1000:-1000 -500:100:0 50:50:200 300:100:3900],...
% 'linestyle','none');

m_grid('box','fancy','grid','none','fontsize',14);
title('m_shadedtelief(x,y,z)','interpreter','none',...
    'fontsize',15,'fontweight','bold')
axb2 = m_contfbar([0.90],[0.2 0.9], elev,[-7000:3500],...
            'axfrac',.02,'endpiece','no','levels','match','edgecolor','none');   
axb2.TickLength = [0.01 0.01]; 
export_fig(gcf,'m_shadedrelief(x,y,z).fig');
export_fig(gcf,'m_shadedrelief(x,y,z).jpg','-r500');

在这里插入图片描述

3. m_etopo2(‘shadedrelief’)

本例展示m_etopo2函数调用‘shadedrelief’选项的绘图效果。本质上m_etopo2(‘shadedrelief’)用法其实是m_etopo2调用 m_shadedrelief函数,因此同样必须先指定caxis colormap,再运行m_shadedrelief !)本例个人感觉运行速度比m_shadedrelief(x,y,z)的用法绘图速度更快一点。

%% P03 m_etopo2('shadedrelief')用法

figure('units','centimeters','position',[1 3 29.7 21]);
set(gcf,'GraphicsSmoothing','off','color','w')
m_proj('miller','lat',[2 24],'lon',[105 125]);

caxis([-7000 3500]);
colormap([m_colmap('blues',256);m_colmap('gland',128)]);
m_etopo2('shadedrelief')
m_grid('box','fancy','grid','none','fontsize',14);
title('m_etopo2(shadedrelief)','interpreter','none',...
    'fontsize',15,'fontweight','bold')
axb3 = m_contfbar([0.90],[0.2 0.9], elev,[-7000:3500],...
            'axfrac',.02,'endpiece','no','levels','match','edgecolor','none');   
axb3.TickLength = [0.01 0.01]; 
export_fig(gcf,'m_etopo2(shadedrelief).fig');
export_fig(gcf,'m_etopo2(shadedrelief).jpg','-r500');

在这里插入图片描述
m_shadedrelief函数还有许多其他可用参数(lightangle gradient等),限于使用经历太少,上面P02与P03都是用的m_shadedrelief的默认参数,可在后续的绘图中尝试多种参数。
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值