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

12 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Pratheek
Pratheek il 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)');

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by