Highlight cells in heatmap

조회 수: 22 (최근 30일)
Ilyass Boukhari
Ilyass Boukhari 2020년 11월 26일
댓글: Ilyass Boukhari 2020년 12월 1일
I created a heatmap where each cell represents a temperature value using the commands:
cdata = [values of temperature]
xvalues = [0,1,2,3,etc.]
yvalues = [0,1,2,3,etc.]
h = heatmap(xvalues,yvalues,cdata)
I need to:
  • command to highlight cells over a limit (for example 500)
  • Highlight cells within a given range (for example 300 to 800)
It is not important how the cells are highlighted, it can be a different colour (like green or blue), or a cross X on top of the cells.
Thanks for the help

채택된 답변

Rishik Ramena
Rishik Ramena 2020년 12월 1일
You can do so by creating a custom colormap. The code below shows a simple implementation.
xvalues = 1:5;
yvalues = 1:5;
cdata = randi(20,[5,5]); % range of values in cells < 20
cmap = [repmat([1 0 0],5,1)
repmat([1 1 1],5,1) % highlight all cells with values from 5-10 with white
repmat([0 0 0],10,1)]; % highlight all cells > 10 with black
heatmap(1:5,1:5,randi(20,[5 5]),'Colormap',cmap);
  댓글 수: 3
Rishik Ramena
Rishik Ramena 2020년 12월 1일
편집: Rishik Ramena 2020년 12월 1일
The second argument for repmat denotes the number of rows to be repeated for the RGB vector given in its first argument. So the cmap contains rows of RGB values which are equal in number to the range of values in the cdata (max-min). For visualisation, try imagining filling the colors on the colorbar from the bottom while creating a custom colormap.
max_val = max(cdata(:)) % get the max value from cdata
cmap = [repmat([1 0 0],200,1) % first 200 rows (0-199)
repmat([1 1 1],750-200,1) % 200-749
repmat([0 0 0],max_val-750,1)]; % >= 750
Ilyass Boukhari
Ilyass Boukhari 2020년 12월 1일
All clear! Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by