Heatmap log-ColorScaling and ColorLimits error
13 views (last 30 days)
Show older comments
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?
1 Comment
Accepted Answer
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]));
More Answers (0)
See Also
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!