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?

46 次查看(过去 30 天)
heatmap(1:5,1:5,randi(250,[5 5]));

采纳的回答

Sandeep Mishra
Sandeep Mishra 2023-6-7
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by