13 - matlab m_map地学绘图工具基础函数 - 介绍创建管理颜色映射的函数m_colmap和轮廓图绘制颜色条的函数m_contfbar

13 - matlab m_map地学绘图工具基础函数 - 介绍创建管理颜色映射的函数m_colmap和轮廓图绘制颜色条的函数m_contfbar


0. 引言

   本篇介绍下m_map用于创建和管理颜色映射函数(m_colmap)和 为轮廓图绘制颜色条的函数(m_contfbar)。

1. 关于m_colmap

  m_colmap函数用于创建和管理颜色映射(colormap)。颜色映射可以用来对数据进行可视化编码,例如在地图上显示温度、高度、速度等信息。

m_colmap函数的一般形式如下:

cols=m_colmap(nme,m,ncol)
% m_colmap  Useful colormaps
%   m_colmap(NAME) returns an M-by-3 matrix containing the NAME colormap
%   where NAME is one of:
%     'jet' : a perceptually uniform variation of the JET colormap. It
%             contains the multiple colours which make JET useful, while
%             avoiding the weird highlighting especially around yellow and
%             cyan. The colors begin with dark blue, range through shades
%             of blue, green, orange and red, and ends with dark red.
%     'mBOD' : a modified blue/orange diverging colormap without white,
%              useful as a colorblind-friendly jet alternative
%
%     'diverging' : a blue/red diverging colormap
%     'BOD' : a blue/orange diverging colormap
%     'rBOD' : a different blue/orange colormap with gray in the middle
%
%     'odv'  : an isoluminant map 
%     'cyclic2': a cyclic colormap (for angles) with two dark regions
%     'cyclic1': a cyclic colormap (for angles) with one dark region
%
%     'land' : a topographic height (green-brown-white) shading
%     'water' : blue shading for water (goes with 'land').
%     'gland' : a topographic height  shading with more green
%     'bland' : a topographic height shading with browns only.
%
%     'blue' : a perceptually useful blue shading (good for bathymetry)
%     'green' : a perceptually useful green shading
%     'chlorophyll': Enhanced green for chlorophyll (to red)
%     'CBchlorophyll': Enhanced green for chlorophyll (to magenta)
%                               <-colorblind friendly
%
%     'EK80' : a standard echo-sounder map.
%     'chart':  the standard chart colour (single color)
%
%   and M is the same length as the current figure's colormap. If no
%   figure exists, the length of the default colormap is used. The
%   length can be explicitly specified with s_colmap(NAME,M).
%
%   m_colmap('demo') demonstrates the colormaps.
%
%   m_colmap(NAME,'step') returns a 256-color map in which colours are
%   perceptually bunched into 16 separate colours. This is useful
%   if you want to see "edges" in what would be an otherwise
%   smooth gradation (i.e. approaching the look of contouring).
%
%   m_colmap(NAME,'demo') Gives a demo of this behavior
%
%   m_colmap(NAME,'step',M) bunches into M colours.

  其中,nme 选择一种颜色类型;m 颜色长度,不设置就自动用默认的,设置了就颜色条按区间进行分段;

  m_map所有颜色类型可以通过下面一句代码查看:

m_colmap demo

m_colmap函数的使用示例,示例数据可以从网盘获取,提取码:ofxi:

%% m_colormap
clc;clear;
ncFilePath = 'GLDAS_NOAH10_M.A200602.021.nc4';
lon = ncread(ncFilePath,'lon');
lat = ncread(ncFilePath,'lat');    
soilmoi_data = ncread(ncFilePath,'SoilMoi0_10cm_inst'); 

[LN,LT]=meshgrid(lon,lat);

m_proj('mercator','long',[69.5 105.5],'lat',[24.5 40.5]);
% 在地图上绘制伪彩色图
m_pcolor(LN,LT, soilmoi_data');

colormap( m_colmap('jet') );
%colormap( m_colmap('jet',10) );

% 添加地图边界、标签和色标
m_gshhs('ic','color',[.5 .5 .5]) % 中等分辨率海岸线
m_gshhs('ir2','color','k')   % 中等分辨率河流
m_grid('linestyle','none','tickdir','out');
colorbar;

  对比下图可以发现,绘制在图右侧的颜色调划分上存在差异,这就是设置了m的差别,根据需要选择合适的命令参数,能够绘出更加符合的图示:



2. 关于m_contfbar

  m_contfbar函数用于添加色标,以示地图上的等值线或填充的数据的颜色对应的数值范围。

  m_contfbar函数的一般形式是:

[ ax,h ] = m_contfbar(lon,lat,DATA,LEVELS)
% M_CONTFBAR Draws a colour bar for contourf plots 
%    M_CONTFBAR([X1,X2],Y,DATA,LEVELS) draws a horizontal colourbar
%    between the normalized coordinates (X1,Y) and (X2,Y) where
%    X/Y are both in the range 0 to 1 across the current axes.
%    Negative values can be used to position outside the axis.
%
%    Differences from COLORBAR are: the bar is divided into solid
%    colour patches exactly corresponding to levels provided by
%    CONTOURF(DATA,LEVELS) instead of showing the whole continuous
%    colourmap, the parent axis is not resized, the axis can be made
%    as large or small as desired, and the presence of values 
%    above/below contoured levels is indicated by triangular pieces
%    (MATLAB 2014b or later).
%
%    M_CONTFBAR(X,[Y1,Y2],...) draws a vertical colourbar
%
%    The DATA,LEVELS pair can also be replaced with CS,CH where
%    [CS,CH]=CONTOURF(DATA,LEVELS).
%
%    M_CONTFBAR(...,'parameter','value') lets you specify extra
%    parameter/value pairs for the colourbar in the usual handle-graphics
%    way. Parameters you might set include 'xticks','xticklabels',
%    'xscale','xaxisloc' (or corresponding y-axis parameters for
%    a vertical colourbar) and 'fontsize'.
%
%    Additional parameter/value pairs allow special customization of the
%    colourbar:
%        'axfrac' : width of the colourbar (default 0.03)
%        'endpiece' : 'yes' (default) or 'no' show triangular
%                      endpieces.
%        'levels' : 'set' (default) shows a colourbar with exactly
%                   the levels in the LEVELS argument. 
%                   'match' shows only the subsect of levels actually
%                   used in the CONTOURF call. E.g., if your data ranges
%                   from (say) 121 to 192, and LEVELS=[10:10:300],
%                   then only levels in 130:10:190 actually appear in both
%                   the CONTOURF and the colourbar.
%         'edgecolor' : 'none' removes edges between colors.
%
%    [AX,H]=M_CONTFBAR(...) returns the handle to the axis AX and to
%    the contourobject H. This is useful to add titles, xlabels, etc.
%
%    M_CONTFBAR(BAX,...) where BAX is an axis handle draws the colourbar
%    for that axis.

其中:

  • lon,lat 控制色标的位置,([lon1 lon2],[lat]…)表示横向色标;([lon1],[lat1 lat2]…)纵向色标;
  • DATA 进行绘图的输入数据;
  • axfrac 设置色标宽度 设置value数值;
  • endpiece 设置结束端,yes 或 no;
  • edgecolor 色标框边缘颜色,可以设置’r’ 、'g’等matlab内置颜色,也可以设置none;

m_contfbar函数的使用示例(在官网示例上不断尝试修改):

m_proj('lambert','lat',[5 24],'long',[105 125]);

set(gcf,'color','w')   % Set background colour before m_image call
caxis([-6000 0]);
colormap(flipud([flipud(m_colmap('blues',10));m_colmap('jet',118)]));
m_etopo2('shadedrelief','gradient',3);
m_gshhs_i('patch',[.8 .8 .8]);
m_grid('box','fancy');
ax=m_contfbar(.97,[.5 .9],[-6000 0],[-6000:100:000],'edgecolor','none','endpiece','no','axfrac ',0.1);
xlabel(ax,'meters','color','k');

  示例运行结果,上边的可选参数可自行修改。


3. 结语

   本篇介绍了用于创建和管理颜色映射函数(m_colmap)和 为轮廓图绘制颜色条的函数(m_contfbar),通过示例展示了各函数的基本用法,对于绘制常见地学图已经够用了,后面如果发现还有其它相关函数再进行补充希望对绘图的你有所帮助






😜
😜😜
😜😜😜😜

  • 20
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咋(za)说

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值