Heatmap - multiple values in same cell

조회 수: 9 (최근 30일)
Tobias Wendlinger
Tobias Wendlinger 2022년 3월 8일
답변: Simon Chan 2022년 3월 8일
Hello,
is it possible to display multiple values in the same heatmap "cell"?
For example I have 3 different entries for a y-value of -51 and a x-value of 1. Can this be plotted similarly to this?
I tried doing it with the heatmap() function, but matlab only displayed one of the three entries for y = -51 & x = 1.
Thanks in advance for your help

답변 (2개)

Bjorn Gustavsson
Bjorn Gustavsson 2022년 3월 8일
You can convert three-valued data into an RGB-image. The simplest way to go about this is something along these lines:
dataRGB = zeros(size(HMdata,1)/3,size(HMdata,2),3); % Here I assume that each cell in y corresponds to 3 values
dataRGB(:,:,1) = HMdata(1:3:end,:);
dataRGB(:,:,2) = HMdata(2:3:end,:);
dataRGB(:,:,3) = HMdata(3:3:end,:);
To easily display this type of plot as an image we will have to normalize the values to the 0-1 range. You can do that for all three components together:
imRGB1 = normalize(dataRGB,'range',[0 1]);
or for each RGB-layer separately:
imRGB3(:,:,3) = normalize(dataRGB(:,:,3),'range',[0 1]);
imRGB3(:,:,2) = normalize(dataRGB(:,:,2),'range',[0 1]);
imRGB3(:,:,1) = normalize(dataRGB(:,:,1),'range',[0 1]);
Then you can display it using for example:
imagesc(imRGB1)
HTH

Simon Chan
Simon Chan 2022년 3월 8일
Not writing data to the same cell, but writing to separate cells as a workaround:
Manually change the YDisplayLabel to let the heatmap similar to what you want.
data = rand(18,3);
h = heatmap(data);
yvalue = [-20,-39,-43,-47,-51,-55];
emptystr = repelem({''},1,length(yvalue));
numstr = arrayfun(@(x) num2str(x),yvalue,'uni',0);
h.YDisplayLabels = reshape(vertcat(emptystr,numstr,emptystr),[],1);

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by