1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| function test
[x,y] = meshgrid(1:25);
z1 = rand(25)*400;
z2 = rand(25)*200;
figure(1)
colormap([jet(64) ; gray(64)])
ax1 = subplot(2,1,1);
pcolor(x,y,z1);
shading flat
ax2 = subplot(2,1,2);
pcolor(x,y,z2);
shading flat
colormap([jet(64) ; gray(64)])
CmLength = length(colormap); % Colormap length
BeginSlot1 = 1; % Beginning slot
EndSlot1 = 64; % Ending slot
BeginSlot2 = EndSlot1+1;
EndSlot2 = CmLength;
CLim1 = get(ax1,'CLim'); % CLim values for each axis
CLim2 = get(ax2,'CLim');
set(ax1,'CLim',newclim(BeginSlot1,EndSlot1,CLim1(1),CLim1(2),CmLength))
set(ax2,'CLim',newclim(BeginSlot2,EndSlot2,CLim2(1),CLim2(2),CmLength))
axes(ax1)
c(1) = colorbar('southoutside');
im = get(c(1),'children');
axes(ax2)
c(2) = colorbar('southoutside');
prop = {'xtick','xticklabel','xlim'};
set(c(2),prop,get(c(1),prop))
copyobj(im,c(2))
function CLim = newclim(BeginSlot,EndSlot,CDmin,CDmax,CmLength)
% Convert slot number and range
% to percent of colormap
PBeginSlot = (BeginSlot - 1) / (CmLength - 1);
PEndSlot = (EndSlot - 1) / (CmLength - 1);
PCmRange = PEndSlot - PBeginSlot;
% Determine range and min and max
% of new CLim values
DataRange = CDmax - CDmin;
ClimRange = DataRange / PCmRange;
NewCmin = CDmin - (PBeginSlot * ClimRange);
NewCmax = CDmax + (1 - PEndSlot) * ClimRange;
CLim = [NewCmin,NewCmax];
end % newclim
end |
Partager