How to change the colorbar limits in Matlab?

106 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 22 Jan 2023
'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.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 22 Jan 2023
clim does the job, e.g.:
surf(peaks)
clim([1.2 2.6])
colorbar

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!