How to get a colorbar to show only a specified range of values?
143 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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]);
0 Commenti
Risposte (2)
Sulaymon Eshkabilov
il 8 Gen 2024
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(:)))
fprintf('MIN value of the data: DMin = %f \n', min(D(:)))
0 Commenti
Voss
il 8 Gen 2024
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()')
0 Commenti
Vedere anche
Categorie
Scopri di più su Blue 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!