Set color to 'none' instead of white in 'heatmap'

조회 수: 19 (최근 30일)
Yue Gu
Yue Gu 2020년 4월 18일
답변: Tommy 2020년 4월 18일
Hi,
I am facing a problem while using 'heatmap' function. Basically, I would like the ''MissingDataColor'' to be none instead of white, as seen below (titled 'Figure 3'). I found some color settings (e.g., ''CellLabelColor'') can be set none. So, it draws my curiosity that if I could modify the other color setting to have the same property.
Overall, I'm trying to render the final exported image to have transparent areas that now are shown white.
Thank you in advance for your help!
Best,
Yue

답변 (1개)

Tommy
Tommy 2020년 4월 18일
Unfortunately 'none' is not a valid value for 'MissingDataColor', and I cannot find any way to set alpha values in heatmaps.
Would something like the following work for you? A unique color (here, pink, but could be anything) is used as the missing data color. Then, after you have finished editing the heatmap however you like, the heatmap is copied to an image. Any pixel in the image whose color equals the unique missing data color is set to transparent using the 'AlphaData' property of an image.
% set up some random data to plot in heatmap
N = 10;
d = randi(10,N);
d(randi(N*N,3,1)) = NaN;
% create heatmap
f = figure;
mC = [255 192 203]; % RGB of color for missing data - should not match any other color in heatmap
h = heatmap(f, d, 'MissingDataColor', mC./255);
% after you are completely done editing heatmap, transfer to image and set image's AlphaData property
c = frame2im(getframe(f)); % color data
a = ones(size(c(:,:,1))); % alpha data
a(c(:,:,1)==mC(1) & c(:,:,2)==mC(2) & c(:,:,3)==mC(3)) = 0; % set alpha data for pixels of missing data to transparent
figure
I = imshow(c);
I.AlphaData = a;

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by