【问题标题】:How to put labels on each data points in stem plot using matlab如何使用matlab在茎图中的每个数据点上放置标签
【发布时间】:2015-02-05 16:22:13
【问题描述】:

这是我的 x 和 y 数据:

x = [29.745, 61.77, 42.57,  70.049, 108.51, 93.1,   135.47, 52.79,  77.91,  116.7,  100.71, 146.37, 125.53]
y = [6, 6, 12,  24, 24, 12, 24, 8,  24, 24, 24, 48, 8]

stem(x,y);

所以我想在我的茎图上标记每个数据点,我想要输出我想要的:

我用油漆编辑它,matlab 可以做这个垂直标签吗?图像是什么样的?请帮忙。

【问题讨论】:

    标签: matlab label scatter-plot


    【解决方案1】:

    是的,它可以!你只需要提供文本注释的rotation属性值为90就可以了。

    例子:

    clear
    clc
    
    
    x = [29.745, 61.77, 42.57,  70.049, 108.51, 93.1,   135.47, 52.79,  77.91,  116.7,  100.71, 146.37, 125.53]
    y = [6, 6, 12,  24, 24, 12, 24, 8,  24, 24, 24, 48, 8]
    
    hStem = stem(x,y);
    
    %// Create labels.
    Labels = {'none'; 'true';'false';'mean';'none';'';'true';'hints';'high';'low';'peas';'far';'mid'}
    
    %// Get position of each stem 'bar'. Sorry I don't know how to name them.
    X_data = get(hStem, 'XData');
    Y_data = get(hStem, 'YData');
    
    %// Assign labels.
    for labelID = 1 : numel(X_data)
       text(X_data(labelID), Y_data(labelID) + 3, Labels{labelID}, 'HorizontalAlignment', 'center','rotation',90);
    end
    

    这给出了以下内容:

    最后一个标签有点高,所以你可能想重新调整坐标轴,但你明白了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-04
      • 2012-08-14
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      相关资源
      最近更新 更多