简体   繁体   English

如何使用Matlab在词干图中的每个数据点上放置标签

[英]How to put labels on each data points in stem plot using matlab

so this is my x and y data: 所以这是我的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);

so i want to label each data point on my stem plot, this i want output i want: 所以我想在干图上标记每个数据点,这是我想要的输出: 在此处输入图片说明

i edit it using paint, can matlab do this vertical labeling? 我使用油漆对其进行编辑,matlab可以进行垂直标注吗? just what the image look like? 图像是什么样的? please help. 请帮忙。

Yes it can! 是的,它可以! You just need to provide the rotation property of text annotations with a value of 90 and it works fine. 您只需要提供值为90的文本注释的rotation属性,它就可以正常工作。

Example: 例:

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

Which gives the following: 给出以下内容:

在此处输入图片说明

The last label is a bit high so you might want to rescale the axes, but you get the idea. 最后一个标签有点高,因此您可能想要重新调整轴的比例,但是您明白了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM