How to change the colorbar limits in Matlab?

187 ビュー (過去 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 件のコメント
Hylke Dijkstra
Hylke Dijkstra 2023 年 1 月 25 日
This is helpful, thanks!

サインインしてコメントする。

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 1 月 22 日
clim does the job, e.g.:
surf(peaks)
clim([1.2 2.6])
colorbar

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by