How to get a colorbar to show only a specified range of values?
조회 수: 103 (최근 30일)
이전 댓글 표시
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1585961/image.png)
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
답변 (2개)
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(:)))
fprintf('MIN value of the data: DMin = %f \n', min(D(:)))
댓글 수: 0
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()')
댓글 수: 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!