How to make the color bar the same color when it is the same variable in two different pictures
11 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Pratheek
on 28 Mar 2023
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)');
0 Comments
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!