フィルターのクリア

heatmap NaN Color replacement BUG

19 ビュー (過去 30 日間)
Nicholas Scott
Nicholas Scott 2024 年 1 月 11 日
編集済み: Austin M. Weber 2024 年 1 月 18 日
Hi Community!
I am trying to grey out diagonals (for ease of viewing-0 being white was not sufficient for my collaborators) without modifying my color map to a custom color map, but am running across a curious issue; here is my code:
heatmap(a_y(1:2,2:3), MWx, MWy, ...
'%0.2f', 'TickAngle', 45, 'Colormap', redblue(100), 'FontSize', 25, 'NaNColor', [0.5 0.5 0.5])
title('Log 10 Relationships of Median Y_{1/2} MDA231 Note: (x/y)')
ax = gca;
ax.FontSize = 16;
ax.FontName = 'Arial';
clim([-0.10 0.10])
colorbar
This produces a heat map that looks incorrect, based on the color bar minimum and maximum value. In fact it treats clim as if it doesn't actually exist for the coloring of the heatmap, but does exist for the colorbar.
alternatively, if I use the code and remove the 'NanColor':
a_y = log10(PC3_y./trans_PC3_y);
a_y(sub2ind(size(a_y), 1:length(a_y), 1:length(a_y))) = NaN; %NaN on diagonals
figure
heatmap(a_y(1:2,2:3), MWx, MWy, ...
'%0.2f', 'TickAngle', 45, 'Colormap', redblue(100), 'FontSize', 25)
title('Log 10 Relationships of Median Y_{1/2} PC3 Note: (x/y)')
ax = gca;
ax.FontSize = 16;
ax.FontName = 'Arial';
clim([-0.10 0.10])
colorbar
I get a correct image, however NaN is considered the minimum value, which just makes a snap interpretation of this more difficult:
I even attempted to adjust the code of heatmap.m, where the code states:
p.addParamValue('NaNColor', [NaN NaN NaN], @(x)isnumeric(x) && length(x)==3 && all(x>=0) && all(x<=1)); %I adjusted [NaN NaN NaN] to 0.5 for all to make it grey
While it was successful in greying out the 1 diagonal in this abreviated heatmap, it messed up the heatmap's coloring just like the first image did. Does anyone know how to grey out without running into that problem?
Thanks,
Nick

採用された回答

Austin M. Weber
Austin M. Weber 2024 年 1 月 18 日
編集済み: Austin M. Weber 2024 年 1 月 18 日
Instead of using the NanColor name-value pair (which I don't even see in the documentation?), you can try saving the plot to an axis handle and use dot indexing to set the MissingDataColor property to the NaN color that you want:
a_y = [-0.03 -0.08; NaN -0.05];
figure
h = heatmap(a_y);
% Quick redblue color map
redblue = flip([1 0 0; 1 0.25 0.25; 1 0.5 0.5; 1 0.75 0.75; 1 1 1; 0.75 0.75 1; 0.5 0.5 1; 0.25 0.25 1; 0 0 1]);
colormap(redblue)
h.MissingDataColor = [0.5 0.5 0.5];
clim([-0.10 0.10])

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by