How to change the colorbar limits in Matlab?
142 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!