修复 clustergram 列标签错位

Fixing a clustergram column label misalignment

在下面的代码中,我尝试用红色突出显示特定的列。然而,如图所示,生成的标签颜色条未与标签对齐。我该如何纠正?

datdat = randn(5,10);
regregnames = {'A', 'B', 'C', 'D', 'E'};
colors = cell(1,size(datdat,2));
for i=1:size(datdat,2)
    colors{i} = [1,1,1];
end
colors{3} = [1,0,0];
s.Labels = arrayfun(@num2str, 1:size(datdat,2), 'UniformOutput', false);
s.Colors = colors;
clscls = clustergram(datdat, 'RowLabels', regregnames, 'ColumnLabels', s.Labels, 'ColumnLabelsColor', s, 'LabelsWithMarkers', true);

这绝对是 MATLAB 中的一个错误。我怎么知道?通过检查 clustergram.plot 函数。

如果我们在第 142 行设置一个断点,positionAxes(obj, imAxes),并且 运行 您的代码直到该点,我们得到下图:

对齐正确,但树状图不可见。然后,代码继续重新定位轴(主要是使它们变小),但不幸的是忽略了带有红色标签的底部。

要了解如何解决此问题,我们应该回顾一下,进入创建此底部栏的 HeatMap.plot > initHMAxes 并找到其句柄的存储位置。那么,我们需要做的就是根据其余的clustergram调整这个元素的positionHeatMap)。

我将继续挖掘 handles/appdata "as an exercise to the reader",但长话短说,只需将其添加到您的代码末尾:

hAx = struct(clscls).HMAxesHandle;
data = getappdata(hAx, 'HeatMapAxesData');
data.XMarkerAxes.Position = data.XMarkerAxes.Position.*[0 1 0 1] + hAx.Position.*[1 0 1 0];

结果:


顺便说一句,在 R2017b 上,我收到以下警告:

Warning: COLUMNLABELSCOLOR is not supported and will be removed in a future release.
Use LabelsWithMarkers for similar functionality.

所以从技术上讲,这不是错误,而是不受支持的功能。