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

统一Matlab下不同子图的色标colorbar

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

Reference:http://www.mathworks.com/matlabcentral/answers/100950-how-can-i-have-a-standard-colorbar-for-different-plots-in-matlab-7-0-4-r14sp2

Question:

    I am trying to compare different sets of data, with different sets of ranges using PCOLOR.    

% Plot # 1
figure(1);
C = rand(5);            % Random values between 0 and 1 for Plot#1
p = pcolor(C);         
colorbar;                 % colorbar is set for figure(1)

% Clears the workspace
clear all;
clc;
% Plot # 2
figure(2);
C = .25*rand(5) + .5;  % Create random values between .375 and .625 for Plot # 2   
p = pcolor(C);              
colorbar;                     % colorbar is set for figure(2)

    

    The COLORBAR function generates a different colorbar for each set of data. Thus, it becomes difficult for me to compare the different data sets, as the ranges and tick labes on the colorbars are different for each data set. So, how can I have a standard colorbar for different plots?

Answer:   

  One soultion is to use set(gca, 'CLim', [cMin cMax])  funciton

In order to have a standard colorbar for plots generated using PCOLOR you first need to set the same ‘CLim’ property for the axes of each plot before you enable the colorbar for that plot (i.e. by executing the COLORBAR command).

     Since the colorbar chooses limits and labels according to the ‘CLim’ property of the associated axes, it is important to create (or recreate) the colorbar after setting the ‘CLim’ property.

For example:

% Plot # 1
figure(1);
a = axes;
C = rand(5);            % Random values between 0 and 1 for Plot#1
p = pcolor(C);         
set(a, 'CLim', [0 1]); % CLim property is set for figure(1) before colobar
colorbar;                 % colorbar is set for figure(1)
% Clears the workspace
clear all;
clc;
% Plot # 2
figure(2);
a = axes;
C = .25*rand(5) + .5;  % Create random values between .375 and .625 for Plot # 2   
p = pcolor(C);             
set(a, 'CLim', [0 1]);    % CLim property is set for figure(2) before colobar 
colorbar;                     % colorbar is set for figure(2)

 Another solution is to use caxis([cmin cmax]) function  

figure(1);
C = rand(5); % Random values between 0 and 1 for Plot#1
p = pcolor(C); 
caxis([0,1]);
colorbar
 
figure(2);
C = .25*rand(5) + .5; % Create random values between .375 and .625 for Plot # 2 
p = pcolor(C); 
caxis([0,1]);
colorbar

  Afte you run the above code, you will observe that both plots share the same colorbar. Results are as follows:


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
DelphiclassTDataSetToExcel发布时间:2022-07-18
下一篇:
Matlab优化存储器读写来改善程序性能发布时间: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