Matlabの異なるサブ図を統一するカラースケールcolorbar

5244 ワード

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 compre different sets of data,with different sets of ranges using PCOLOOR.    
% 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)
 统一Matlab下不同子图的色标colorbar  统一Matlab下不同子图的色标colorbar
    The COLORBAR function generant a different colorbar for each set of data.Thus、it becocococococococococompes difficult for me to cofferent data sets、as the ranges and tick labes on the colorbars ars ars ar ararar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar arch ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar ar
Answer:   
  One soultion is to use set(gca,‘CLim’,[cMin cMax])  funciton
In order to have a standard colorbar for plots generated using PCOLPOR You first need to set the same‘CLim’propertyfor the axes of each plot before you enable the colorbar for at plot(i.e.by.extrant)Colorbar for colorver.COlorver.Colorbar for
     Since the colorbar choses limits and labes according to the‘CLim’property of the assicated axes,it is importt 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]) 機能  
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 ars are as follows:
统一Matlab下不同子图的色标colorbar