Select cells in heatmap

11 次查看(过去 30 天)
Ilyass Boukhari
Ilyass Boukhari 2020-11-29
I created a heatmap with given values using the code below
cdata = [values of temperature]
xvalues = [0,1,2,3,etc.]
yvalues = [0,1,2,3,etc.]
h = heatmap(xvalues,yvalues,cdata)
I need a code to automatically select cells above a limit. (for example, select cells above value 500)
I am looking to highlight the cell with a simple cross on top or a different color, like green. it is not essential how they are highlighted so I am happy to hear any other suggestion
Thank you in advance

回答(1 个)

Divija Aleti
Divija Aleti 2020-12-4
Hi Ilyass,
You can change the 'ColorLimits' property of the HeatmapChart so that all the values of 'cdata' that are equal to and above the upper limit will have the same color. To specify this color, you can append its RGB values as a row vector to the Colormap of your choice.
For example, have a look at this example code and its output, where the Colormap chosen was 'autumn' and all the values equal to and greater than 60 are highlighted in green :
cdata = [45 60 32; 43 54 76; 32 94 68; 23 95 58];
xvalues = {'Small','Medium','Large'};
yvalues = {'Green','Red','Blue','Gray'};
mymap = [autumn; 0 1 0]; % Green - [0 1 0]
h = heatmap(xvalues,yvalues,cdata,'Colormap',mymap);
h.ColorLimits = [20 60];
h.Title = 'T-Shirt Orders';
h.XLabel = 'Sizes';
h.YLabel = 'Colors';
Output:
Hope this helps!
  1 个评论
Ilyass Boukhari
Ilyass Boukhari 2020-12-4
hello and thanks for helping!
In your example, is there any way to highlight green in the middlerange only?(example 40 to 45 in green, and all the rest in 'autumn')

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by