フィルターのクリア

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 ビュー (過去 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 Center および File ExchangeData Distribution Plots についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by