MATLAB 中的方形热图

问题描述 投票:0回答:0

我正在使用 Lucas G. S. Jeub 的 HierarchicalConsensus MATLAB 包 中的 consensusPlot.m 函数来创建右侧带有树状图的热图。我输入一个方阵

C
并希望热图是正方形的。然而,consensusPlot.m 函数默认返回矩形热图。

这里是样本数据和修改后的 consensusPlot.m 以及相关函数。下面是代码:

% Load data
ScTree = load('ScTree.mat');
Sc = ScTree.Sc;
Tree = ScTree.Tree;
C = load('C.mat');
C = C.C;

% Draw heatmap
consensusPlot(C, Sc, Tree);
set(gcf, 'PaperSize', [6 6]);
print(gcf, '-dpdf', 'Fig.pdf');

我查看了 consensusPlot.m 函数并找到了以下与创建热图最相关的代码片段:

parseArgs=inputParser();
addParameter(parseArgs,'GroundTruth',[]);
addParameter(parseArgs,'Labels',{});
addParameter(parseArgs,'LabelFont',6);
addParameter(parseArgs,'ImageRescale',1);
parse(parseArgs,varargin{:});
Sgtruth=parseArgs.Results.GroundTruth;
labels=parseArgs.Results.Labels;
ylabelfont=parseArgs.Results.LabelFont;
imrescale=parseArgs.Results.ImageRescale;
clf()
ax_C_int=axes('position',[0.1,0.1,0.7,0.8]);
ax_H_int=axes('position',[0.8,0.1,0.1,0.8]);

N=length(C);
ylims=[0.5+0.5*1/imrescale,N+0.5-0.5*1/imrescale];
s_int=treeSort(C,Sc,Tree);
imagesc(ax_C_int,ylims,ylims, imresize(C(s_int,s_int),imrescale,'nearest'));
if ~isempty(labels)
    set(ax_C_int,'ytick',1:N,'yticklabel',labels(s_int),...
        'xtick',1:N,'xticklabel',labels(s_int),'xticklabelrotation',90,...
        'ticklabelinterpreter','None','fontsize',ylabelfont)
end

热图在左侧,树状图在最终图像的右侧。热图的默认宽度为 0.7,默认高度为 0.8。当我设置

ax_C_int=axes('position',[0.1,0.1,0.7,0.7]);
时,热图变得更加拉长。我想知道我应该如何修改原始代码来创建方形热图。

我有两个额外要求:

  1. 热图和树状图之间不能有空格;

  2. 我修改了代码,在热图下方添加了与热图等宽的颜色条。我想确保当热图变成正方形时,颜色条与热图的宽度保持相等。

matlab heatmap matlab-figure image-scaling
© www.soinside.com 2019 - 2024. All rights reserved.