matlab scatter和plot,scatterplot可视化matlab中的相同点

你可以很容易地做到这一点,让我们分两部分:

首先,您需要确定唯一的2d点并计算它们.这就是我们拥有的unique和accumarray功能.如果您没有立即了解他们正在做什么以及他们有什么输出,请仔细阅读文档:

x = [11 10 3 8 2 6 2 3 3 2 3 2 3 2 2 2 3 3 2 2];

y = [29 14 28 19 25 21 27 15 24 23 23 18 0 26 11 27 23 30 30 25];

A=[x' y'];

[Auniq,~,IC] = unique(A,'rows');

cnt = accumarray(IC,1);

现在Auniq的每一行包含唯一的2d点,而cnt包含每个点的出现次数:

>> [cnt Auniq]

ans =

1 2 11

1 2 18

1 2 23

2 2 25

1 2 26

...etc

为了显示出现的次数,有很多可能性.正如你所提到的,你可以将数字放在散点标记内/旁边,其他选项是颜色编码,标记的大小,……让我们做所有这些,你当然也可以组合!

标记旁边的数字

scatter(Auniq(:,1), Auniq(:,2));

for ii=1:numel(cnt)

if cnt(ii)>1

text(Auniq(ii,1)+0.2,Auniq(ii,2),num2str(cnt(ii)), ...

'HorizontalAlignment','left', ...

'VerticalAlignment','middle', ...

'FontSize', 6);

end

end

xlim([1 11]);ylim([0 30]);

标记内的数字

scatter(Auniq(:,1), Auniq(:,2), (6+2*(cnt>1)).^2); % make the ones where we'll put a number inside a bit bigger

for ii=1:numel(cnt)

if cnt(ii)>1

text(Auniq(ii,1),Auniq(ii,2),num2str(cnt(ii)), ...

'HorizontalAlignment','center', ...

'VerticalAlignment','middle', ...

'FontSize', 6);

end

end

正如您所看到的,我使用散射函数本身非常简单地扩大了标记的大小.

颜色编码

scatter(Auniq(:,1), Auniq(:,2), [], cnt);

colormap(jet(max(cnt))); % just for the looks of it

之后,您可以添加colorbar或legend以指示每种颜色的出现次数.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值