How to change the colorbar limits in Matlab?

조회 수: 166 (최근 30일)
Hylke Dijkstra
Hylke Dijkstra 2023년 1월 22일
댓글: Hylke Dijkstra 2023년 1월 25일
Dear all,
I want to apply log scaling to my colormap because the data I have is heavily skewed. My code is the following:
A = rand(1435);
h = heatmap(A, 'Colormap',flip(hot),'ColorScaling','log','ColorLimits',[10^-5 10^0], 'ColorMethod','none');
XLabels = 1:1435;
YLabels = 1:1435;
% Convert each number in the array into a string
CustomXLabels = string(XLabels);
CustomYLabels = string(YLabels);
% Replace all but the fifth elements by spaces
CustomXLabels(mod(XLabels,1436) ~= 0) = " ";
CustomYLabels(mod(YLabels,1436) ~= 0) = " ";
% Set the 'XDisplayLabels' property of the heatmap
% object 'h' to the custom x-axis tick labels
h.XDisplayLabels = CustomXLabels;
h.YDisplayLabels = CustomYLabels;
clim([10^-5 10^0]);
grid off
Note that my A matrix is in my case different, but for this example I do not have to share my data. The problem that I have is that the colorbar for this heatmap ranges from a little below 1.2 to slightly above 2.6. Since all my numbers are between 0 and 1 this is not what I want. I want log scaling between the numers 10^-5 and 10^0. I tried to use ColorLimits and clim but it does not seem to do the trick..
Any help would be appreciated!
Best

채택된 답변

Walter Roberson
Walter Roberson 2023년 1월 22일
'ColorScaling','log','ColorLimits',[10^-5 10^0]
When you specify colorscaling log, the colorlimits are the logs of the limits -- so you ended up with exp(1e-5) to exp(1) as your limits.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 1월 22일
clim does the job, e.g.:
surf(peaks)
clim([1.2 2.6])
colorbar

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by