• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

matlab中如何使不同图片的colorbar范围相同,刻度显示极值,不同图的colorbar色标相同 ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1:请问matlab中画多张图如何使用同一范围的colorbar?

例如生成了图1,2,3

生成图1时,使用

temp1=caxis;

将图1的z值的取值范围(即colorbar的取值范围)取出。

生成图2,3时

使用

caxis(temp1)

命令将图2,3的z值的取值范围设为同1相同。

然后对各个同使用colorbar命令便可以了。

解释:matlab将z值映射到colormap,colorbar通过z值和colormap的映射关系生成的,所以需要
    将不同的figure,z值映射相同的colormap索引。

命令:
caxis

caxis([cmin cmax])

caxis controls the mapping of data values to the
colormap.

 

2:colorbar的刻度经常达不到极值,可以使用下面的方法达到极值

figure

[x,y,z]=peaks(20);

subplot(2,1,1),contourf(x,y,z),colorbar

subplot(2,1,2),contourf(x,y,z)

t1=caxis;

t1=linspace(t1(1),t1(2),6);

my_handle=colorbar(\'ytick\',t1);

 

再比如:

load topo

subplot(\'position\',[0 0.5 1 0.45 ])
axesm robinson
meshm(topo,topolegend)
demcmap(caxis)
h=colorbar(\'northoutside\');
t=get(h,\'xtick\');

subplot(\'position\',[0 0.05 1 0.45 ])
axesm robinson
meshm(topo,topolegend)
a=caxis;
demcmap(caxis)
colorbar(\'northoutside\',\'xtick\',[a(1),t,a(2)])

 

其结果如下:

下面程序给出地形和大地水准面的结果:

load topo
load geoid
load coast

subplot(\'position\',[0 0.5 1 0.45 ])
axesm robinson
meshm(topo,topolegend)
plotm(lat,long)
a=caxis;
demcmap(caxis)
colorbar(\'northoutside\',\'xtick\',[a(1),-6000:2000:4000,a(2)])


subplot(\'position\',[0 0.05 1 0.45 ])
axesm robinson
meshm(geoid,geoidlegend)
plotm(lat,long)
demcmap(caxis)
a=caxis;
h=colorbar(\'northoutside\',\'xtick\',[ceil(a(1)),-80:20:60,floor(a(2))]);

 

 另外,当图形窗口小时,用colorbar做出了刻度,当将图形窗口放大时,会发现刻度值重复出现或有错误。要消失其错误,现在还没有好的方法。只能首先用大的窗口打开,然后再colorbar。

 

 

3:不同图的colorbar色标相同,但是colorbar的刻度范围不同

matlab如何使不同的colorbar的相同颜色代表相同的数值?
但是同时,每个colorbar显示的最大最小值又是不同的。
比如
图1中colorbar刻度的范围是[-5e3,5e3]
而图2中colorbar刻度的范围是[-1e3,1e3]
即,图2的colorbar的颜色范围只是图1color把人颜色范围的一部分?

 

解决方案:

set(gca,\'CLim\',[a,b])

用来使不同的图使用相同的色标

caxis([a,b])达到同样的效果:


CLim
   

[cmin, cmax]

Color axis limits. Determines how MATLAB maps the CData values of surface and patch objects to the figure\'s Colormap. cmin is the value of the data mapped to the first color in the colormap. cmax is the value of the data mapped to the last color in the colormap. MATLAB linearly interpolates data values in between across the colormap and clamps data values outside to either the first or last alphamap colormap color, whichever is closest.

When CLimMode is auto (the default), MATLAB assigns cmin the minimum data value and cmax the maximum data value in the graphics object\'s CData. This maps CData elements with minimum data value to the first colormap entry and with maximum data value to the last colormap entry.

If the axes contains multiple graphics objects, MATLAB sets CLim to span the range of all objects\' CData.

See the caxis function reference page for related information.

 

 

接下来控制colorbar的范围:

set(h,colorbar,\'ylim\',[a0,b0])便可以了

 


试试两者差异
 surf(peaks(30)); colormap jet; colorbar
 surf(peaks(30)); colormap jet; h=colorbar;set(h,\'Ylim\',[0,6])
 
若连原来图的颜色亦想控制, 试
 surf(peaks(30)); colormap jet; caxis([0,6]); h=colorbar; set(h,\'Ylim\',[0,6]);

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab实现直方图均衡化发布时间:2022-07-18
下一篇:
Matlab电子书pdf合集发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap