【问题标题】:In matlab how do I change the column and row markers in a heatmap在matlab中如何更改热图中的列和行标记
【发布时间】:2018-02-26 08:24:02
【问题描述】:

我有一些数据存储在 10x11 双倍中。我希望 x 轴上的这些标签乘以 30000 并从 0 开始,而我希望 y 轴上的标签从 1 开始并用 1 缩放。 因此,假设我们有以下内容:

a=rand(10,11);
heatmap(a)

生成以下热图

我希望 x 轴标记为 0,30000,60000.... 并且 y 轴保持原样。有人知道该怎么做吗?

我还想用某种名称(比如 var1 和 var2)标记两个轴。

这是在 Matlab R2017a 中。

【问题讨论】:

    标签: matlab plot heatmap


    【解决方案1】:

    从 R2017b 开始,您可以使用 heatmap 对象的 XDisplayLabels 属性

    a=rand(10,11);
    hm = heatmap(a);
    % Change x axis tick labels to some array
    % hm.XDisplayLabels = [0:3e4:(numel(hm.XDisplayLabels)-1)*3e4];
    % Change x axis tick labels to the current labels * 3e4 (same result)
    hm.XDisplayLabels = str2double(hm.XDisplayData)*3e4 - 3e4;
    
    % To add axes labels to *most* chart types in MATLAB, use `XLabel` and `YLabel` properties
    hm.XLabel = 'var2';
    hm.YLabel = 'var1';
    

    输出:

    R2017a 中引入的heatmap 对象在R2017b 中有更多选项,即XDisplayLabels 在R2017a 中不存在!您最好使用旧版(R2009b - 存在)HeatMap 对象(请注意此处区分大小写)。它不那么漂亮但更可定制......

    % Create legacy heatmap
    hm = HeatMap(a);
    hm.Colormap = bone; % Change colours
    % Add y and x tick labels
    hm.RowLabels = 10:-1:1;
    hm.ColumnLabels = (0:10)*3e4;
    % Slant the labels
    hm.ColumnLabelsRotate = 50;
    
    % This HeatMap is one of the few plots without XLabel and YLabel! 
    % use addXLabel and addYLabel instead
    hm.addXLabel('var2');
    hm.addYLabel('var1');
    

    输出:

    【讨论】:

    • hm.XDisplayLabels = str2double(hm.XDisplayData)*3e4 - 3e4;给出错误但 hm.XLabel = 'number of images'; hm.YLabel = '颜色一致性权重';做工作。如果我删除 xdisplaylabels 行。
    • 谢谢你的解释。
    • 不用担心,在它是一个发生了很大变化的新功能和与旧功能非常相似的命名之间,我并不奇怪会有一些混乱!
    猜你喜欢
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多