matlab中如何使不同圖片的colorbar范圍相同,刻度顯示極值,不同圖的colorbar色標相同


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]);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM