How to make the color bar the same color when it is the same variable in two different pictures

조회 수: 11 (최근 30일)
figure(1)
set(gcf, 'color', 'w', 'Units', 'Normalized', 'OuterPosition', [0.1 0.1 0.8 0.5]);
subplot(1,2,1)
contourf(lon_97_1,lat_97_1,ssta_97_1,'linecolor','k')
colorbar
xlabel('Longitude(^o)');
ylabel('Latitude(^o)');
subplot(1,2,2)
contourf(lon_00_1,lat_00_1,ssta_00_1,'linecolor','k')
colorbar
xlabel('Longitude(^o)');
ylabel('Latitude(^o)');
I want to know how to make variables have the same color when they represent the same value

답변 (1개)

Pratheek
Pratheek 2023년 3월 28일
In this modified code, we are first using the min and max methods to find the ssta variable's minimum and maximum values, across both datasets. The colour limits for both colour bars are then set to these minimum and maximum values using the caxis function. By doing this, the colour scale for both colour bars can be maintained.
figure(1)
set(gcf, 'color', 'w', 'Units', 'Normalized', 'OuterPosition', [0.1 0.1 0.8 0.5]);
% Determine the maximum and minimum values of the ssta variable in both datasets
caxis_min = min([min(ssta_97_1(:)), min(ssta_00_1(:))]);
caxis_max = max([max(ssta_97_1(:)), max(ssta_00_1(:))]);
subplot(1,2,1)
contourf(lon_97_1,lat_97_1,ssta_97_1,'linecolor','k')
colorbar
caxis([caxis_min, caxis_max]); % Set the color limits for the first color bar
xlabel('Longitude(^o)');
ylabel('Latitude(^o)');
subplot(1,2,2)
contourf(lon_00_1,lat_00_1,ssta_00_1,'linecolor','k')
colorbar
caxis([caxis_min, caxis_max]); % Set the color limits for the second color bar
xlabel('Longitude(^o)');
ylabel('Latitude(^o)');

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by