首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于matlab的散点图自动标注

基于matlab的散点图自动标注
EN

Stack Overflow用户
提问于 2015-02-21 19:11:47
回答 2查看 412关注 0票数 0

所以为了继续我刚才的问题,有了这个建议的程序:

代码语言:javascript
复制
%// 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))

因此,它将生成一个数组和一个类似于这样的图:

代码语言:javascript
复制
     a     b     d     counts
     2     1     5     2
     1     3    10     1
     0     5    25     2
     1     1     2     2

D与计数

但是我想把(a,b)作为每个散点点上的标签,所以这是我想要的图:

因此,当您看到相应的a,b将自动标记在每个散点点上,请帮助谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-21 19:35:20

我会使用sprintf和一个简单的for循环来完成它。

完整代码:

代码语言:javascript
复制
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);

输出:

票数 1
EN

Stack Overflow用户

发布于 2015-02-21 19:40:17

在你有了out之后,你可以使用这个no-loop approach -

代码语言:javascript
复制
%// Plot points and set x-y limits
scatter(out(:,3), out(:,4),'o')
xlim([0 30]), ylim([0 2.5])

%// Create string labels
L = cellstr(strcat(strtrim(num2str(out(:,1))),strtrim(num2str(out(:,2)))))

%// Set some y-shift and put text labels
y_shift = 0.1
text(out(:,3),out(:,4)+y_shift,L)
set(gca,'YGrid','on')

代码运行-

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28650118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档