Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
heatmap(1:5,1:5,randi(250,[5 5]));

Réponse acceptée

Sandeep Mishra
Sandeep Mishra le 7 Juin 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.

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by