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
0 个评论
回答(1 个)
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)');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!