Heatmap log-ColorScaling and ColorLimits error

13 views (last 30 days)
I'm trying to make 2 log-scale heatmaps with the same colorbar limits.
I've called the following functions:
figure(1)
heatmap(LeftR0, 'colormap', jet, 'CellLabelFormat', '%.1e');
set(gca, 'ColorScaling', 'log');
clim([4e2, 5e7]);
set(gca, 'FontSize', 18)
set(gcf, 'Position', [100, 100, 600, 450])
which produces the attached graph and throws the following error:
"Warning: Error updating HeatmapChart.
Error setting property 'Limits' of class 'ColorBar':
Value must be a 1x2 vector of numeric type in which the second element is larger than the first."
It seems these 2 functions are incompatible and produces a flat colormap.
What would the correct functions be in order to get both custom colorbar limits and log-scale colorbar to work together?

Accepted Answer

Mathieu NOE
Mathieu NOE on 13 Dec 2023
I don't know , maybe this ??
% Create log values and generate heatmap
dim = 9; % just so the data labels show up
x = logspace(2,8,dim);
values = repmat(x',[1,2]);
figure;
hm = heatmap(values);
% Make visually clearer
hm.GridVisible = 'off';
colormap default
ax1 = gca;
ax1.XDisplayLabels = nan(length(ax1.XDisplayData),1);
ax1.YDisplayLabels = nan(length(ax1.YDisplayData),1);
% Colour bar scaling
set(gca,'ColorScaling','log') % Log scale
caxis(log([4e2 5e7]));
  1 Comment
Ryan Goul
Ryan Goul on 22 Dec 2023
This worked great, thanks Mathieu.
So when 'caxis' or 'clim' function is called and the axis is in 'log-scale' it expects logarithmic scale inputs, and won't automatically scale linear inputs down.

Sign in to comment.

More Answers (0)

Categories

Find more on Color and Styling in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!