How can I somehow highlight (with a specific color, for example) some cells in a heatmap, like only those whose values meet a condition, such as > 200?
31 views (last 30 days)
Show older comments
Laura Gianolio
on 1 Jun 2023
Commented: Laura Gianolio
on 8 Jun 2023
heatmap(1:5,1:5,randi(250,[5 5]));
0 Comments
Accepted Answer
Sandeep Mishra
on 7 Jun 2023
Hello Laura,
I understand that you want to create a heatmap for some range of values and want to highlight some specific cells with values greater than the threshold 200.
In MATLAB, “heatmap" provides you with the functionality to create a heatmap chart with specified values and add colors to them based on those values.
To customize the color of the cells, you can use the “Colormap” parameter and create a custom colormap.
Here's one way to create a custom colormap with a threshold and maxValue value.
% Setting up threshold and maxValue
threshold = 200;
maxVal = 250;
% Custom color map
cmap = [];
% Generating default heatmap till threshold
for i=1:threshold+1
cmap = [cmap; 1 - 0.0035*i , 1 - 0.0020*i, 1-0.0009*i];
end
% Adding different color (red) for values > threshold
cmap = [cmap; repmat([1 0 0], maxVal-threshold-1, 1)];
% plots heatmap with cmap as colormap
figure();
h=heatmap(1:5, 1:5, randi(maxVal,[5 5]));
h.Colormap = cmap;
% set the clim:
clim([0 maxVal]);
You can refer to the below documentation to learn more about "Colormap" in MATLAB.
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots 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!