Filter löschen
Filter löschen

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 Ansichten (letzte 30 Tage)
heatmap(1:5,1:5,randi(250,[5 5]));

Akzeptierte Antwort

Sandeep Mishra
Sandeep Mishra am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by