フィルターのクリア

How to get a colorbar to show only a specified range of values?

103 ビュー (過去 30 日間)
Charlie
Charlie 2024 年 1 月 8 日
回答済み: Voss 2024 年 1 月 8 日
I'm plotting a data set with a wide range of values (10 to 100000), but I only want to plot the values 10 to 300
Is there a way to have both the plotted data and colorbar range to 10-300, and rescale the colors to just this range? This is what I currently have.
contourf(X_ert, Z_ert, log(ert_interp), ncont, 'edgecolor', 'none');
colormap('jet');
cb = colorbar('FontSize', 18, 'YTick', log([10 50 100 200 300]), 'YTickLabel', [10 50 100 200 300]);

回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024 年 1 月 8 日
Use caxis() command. E.g.:
% Create a data set:
D = rand(200, 200) * 1e5 + 10;
% Visualize the data set:
imagesc(D)
% Assign the colorbar scale/range to: 10.. to .. 300
caxis([10 300])
% Add colorbar:
colorbar
xlabel('X')
ylabel('Y')
title('Data Plot')
fprintf('MAX value of the data: DMax = %f \n', max(D(:)))
MAX value of the data: DMax = 100008.594421
fprintf('MIN value of the data: DMin = %f \n', min(D(:)))
MIN value of the data: DMin = 10.131180

Voss
Voss 2024 年 1 月 8 日
Use clim(). Example:
% made up variable values:
X_ert = 1:550;
Z_ert = 2080:2180;
ert_interp = exp(cosd(X_ert(ones(numel(Z_ert),1),:))*10);
min_val = min(ert_interp(:));
max_val = max(ert_interp(:));
ert_interp = (ert_interp-min_val)./(max_val-min_val)*(100000-10)+10;
ncont = 64;
figure
subplot(2,1,1)
contourf(X_ert, Z_ert, log(ert_interp), ncont, 'edgecolor', 'none');
colormap('jet');
cb = colorbar('FontSize', 18, 'YTick', log([10 50 100 200 300]), 'YTickLabel', [10 50 100 200 300]);
title('Without clim()')
subplot(2,1,2)
contourf(X_ert, Z_ert, log(ert_interp), ncont, 'edgecolor', 'none');
colormap('jet');
cb = colorbar('FontSize', 18, 'YTick', log([10 50 100 200 300]), 'YTickLabel', [10 50 100 200 300]);
clim(log([10 300]))
title('With clim()')

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by