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

19 次查看(过去 30 天)
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