本文介绍了使用Matlab在散点图中自动标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在继续我的问题前,有了这个建议的程序:
so in continuation of my problem a while ago, having this suggested program:
%// Input
A =[
2 1 5
1 3 10
1 -2 5
0 5 25
5 0 25
1 1 2
-1 -1 2]
[unqcol3,unqidx,allidx] = unique(A(:,3),'stable')
counts = sum(bsxfun(@eq,A(:,3),unqcol3.'),1) %//'
out =[A(unqidx,:) counts(:)]
scatter(out(:,3), out(:,4))
因此它将生成一个数组和一个像这样的图:
so it will generate an array and a plot like this:
a b d counts
2 1 5 2
1 3 10 1
0 5 25 2
1 1 2 2
d与计数
但是我想在每个散点上放置(a,b)作为标签,所以我想把这个图放出来:
but i want to put (a,b) as a labels on each scatter point, so this the plot out put i want:
如您所见,相应的a,b将在每个散点上自动标记,请帮助谢谢.
so as you can see the corresponding a,b will automatically labelled on each scatter points, please help thanks.
推荐答案
我会使用sprintf
和一个简单的for循环来实现.
I would do it using sprintf
and a simple for loop.
完整代码:
clear
clc
A =[
2 1 5
1 3 10
1 -2 5
0 5 25
5 0 25
1 1 2
-1 -1 2]
[unqcol3,unqidx,allidx] = unique(A(:,3),'stable');
counts = sum(bsxfun(@eq,A(:,3),unqcol3.'),1);
out =[A(unqidx,:) counts(:)]
scatter(out(:,3), out(:,4));
%// This step is not necessary but its easier to understand using it.
a = out(:,1);
b = out(:,2);
x = out(:,3);
y = out(:,4);
for k = 1:size(out,1)
T{k} = sprintf('%i%i',a(k),b(k))
end
%// Determine x- and y-shift to place text relative to the scatter point
xshift = 0.03; yshift = 0.03;
%// Place the text
text(x+xshift, y+yshift, T);
输出:
这篇关于使用Matlab在散点图中自动标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!