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

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

时间:2024-07-14 18:28:05浏览次数:17  
标签:blue map 颜色 函数 contfbar colmap colormap

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),通过示例展示了各函数的基本用法,对于绘制常见地学图已经够用了,后面如果发现还有其它相关函数再进行补充希望对绘图的你有所帮助






标签:blue,map,颜色,函数,contfbar,colmap,colormap
From: https://blog.csdn.net/weixin_43339605/article/details/140248114

相关文章

  • CDF累积分布函数和PPF百分点位分布函数
    目录cdf累积分布函数(CDF)ppf百分位点函数(PPF)区别与联系示例关系和区别cdf累积分布函数(CDF)定义:累积分布函数F(x......
  • 分库分表策略深入解析:基于范围(Range)、基于哈希(Hash)以及基于映射表(Mapping Table)
    目录前言   1.基于范围的分库分表(Range)2.基于哈希的分库分表(Hash)3.基于映射表的分库分表(MappingTable)前言     分库分表是数据库优化中的一项重要技术,它通过将数据分散到多个数据库或表中,以提高系统的处理能力和响应速度。本篇将详细解析三种常见的分库......
  • Java笔记之HashMap
    HashMap的实现原理HashMap概述HashMap是基于哈希表的Map接口的非同步实现。此实现提供所有可选的映射操作,并允许使用null值和null键。此类不保证映射的顺序,特别是它不保证该顺序恒久不变。HashMap实际上是一个“链表散列”的数据结构,即数组和链表的结合体。HashMap底层就是一......
  • Nuxt.js 错误侦探:useError 组合函数
    title:Nuxt.js错误侦探:useError组合函数date:2024/7/14updated:2024/7/14author:cmdragonexcerpt:摘要:文章介绍Nuxt.js中的useError组合函数,用于统一处理客户端和服务器端的错误,提供statusCode、statusMessage和message属性,示例展示了如何在组件中使用它来捕获和显......
  • Python函数(1)--自定义函数与作用域
    函数的定义Python中的函数是一段组织好的、可重复使用的、用来实现单一或相关联功能的代码块。函数能提高应用的模块性,和代码的重复可用性。你已经知道Python提供了许多内建函数,比如print()。但你也可以自己创建函数,这被称为用户自定义函数。自定义函数假设,我们现在求一......
  • C#面:dot net core管道里面的map拓展有什么作用?
    在.NETCore管道中,Map拓展方法用于将中间件添加到请求处理管道中。它的作用是根据请求的路径或其他条件来选择性地执行中间件。具体来说,Map方法接受一个路径参数和一个委托参数。当请求的路径与指定的路径匹配时,该委托中的中间件将被执行。这使得我们可以根据不同的路径来应用......
  • js 一个函数有几种类型的属性
    在JavaScript中,函数对象可以拥有多种类型的属性。主要可以分为以下几类:实例属性(Instanceproperties):这些属性是在通过函数构造函数创建实例时绑定到实例上的属性。原型属性(Prototypeproperties):这些属性是绑定到函数对象的原型上的属性。实例可以通过原型链访问这些......
  • es5 js函数有哪几种继承方式
    在ES5(ECMAScript5)中,JavaScript函数有几种继承方式,主要是通过原型链实现的。以下是常见的几种继承方式:原型链继承(PrototypeInheritance):原理:通过将子类的原型对象设置为父类的实例来实现继承。特点:可以继承父类的实例方法和属性,但无法实现多继承。示例:functionParent(na......
  • 函数式编程的交响曲:探索LangChain对函数式编程特性的支持
    函数式编程的交响曲:探索LangChain对函数式编程特性的支持引言在现代软件开发中,函数式编程(FunctionalProgramming,FP)以其独特的优势,如无副作用、易于并行处理等,逐渐受到开发者的青睐。LangChain作为一个多语言编程工具链,其设计理念在于支持多种编程范式,包括函数式编程。......
  • 对象的生存期 内存 深度拷贝 拷贝构造函数 笔记
    栈上的东西如何存在?栈是类似一种数据结构,像摞在桌子上的一堆书,要看中间的书需要把上面的书拿走作用域:形象成一本书,书内声明的变量作用域结束,要把这本书从书堆中拿出来作用域指针是什么:基本是个类是一个指针的包装器,在构造时用堆分配指针析构时删除指针,可以实现自动化new......