通过点聚类着色的等高线图 [英] Contour plot coloured by clustering of points matlab

查看:89
本文介绍了通过点聚类着色的等高线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个成对的向量

size(X)=1e4 x 1; size(Y)=1e4 x 1

是否可以通过最高密度的点来绘制某种使轮廓成为轮廓的contour plot?即最高聚类=红色,然后在其他地方渐变颜色?

Is it possible to plot a contour plot of some sort making the contours by the highest density of points? Ie highest clustering=red, and then gradient colour elsewhere?

如果您需要更多说明,请询问. 问候

If you need more clarification please ask. Regards,

示例数据:

X=[53 58 62 56 72 63 65 57 52 56 52 70 54 54 59 58 71 66 55 56];  
Y=[40 33 35 37 33 36 32 36 35 33 41 35 37 31 40 41 34 33 34 37 ];
 scatter(X,Y,'ro');

感谢大家的帮助.还记得我们可以使用hist3:

Thank you for everyone's help. Also remembered we can use hist3:

x={0:0.38/4:0.38}; % # How many bins in x direction
y={0:0.65/7:0.65}; % # How many bins in y direction

ncount=hist3([X Y],'Edges',[x y]);
pcolor(ncount./sum(sum(ncount)));
colorbar

有人知道为什么hist3中的edges必须是细胞吗?

Anyone know why edges in hist3 have to be cells?

推荐答案

这基本上是一个有关估计概率密度函数以生成数据,然后以一种很好且有意义的方式对其进行可视化的问题.为此,我建议使用比直方图更平滑的估计,例如Parzen窗口化(直方图方法的一般化).

This is basically a question about estimating the probability density function generating your data and then visualizing it in a good and meaningful way I'd say. To that end, I would recommend using a more smooth estimate than the histogram, for instance Parzen windowing (a generalization of the histogram method).

在下面的代码中,我使用了示例数据集,并根据数据范围估算了网格中的概率密度.您这里需要调整3个变量以用于原始数据.边框,Sigma和stepSize.

In my code below, I have used your example dataset, and estimated the probability density in a grid set up by the range of your data. You here have 3 variables you need to adjust to use on your original data; Borders, Sigma and stepSize.

Border = 5;
Sigma = 5;
stepSize = 1;

X=[53 58 62 56 72 63 65 57 52 56 52 70 54 54 59 58 71 66 55 56];  
Y=[40 33 35 37 33 36 32 36 35 33 41 35 37 31 40 41 34 33 34 37 ];
D = [X' Y'];
N = length(X);


Xrange = [min(X)-Border max(X)+Border];
Yrange = [min(Y)-Border max(Y)+Border];


%Setup coordinate grid
[XX YY] = meshgrid(Xrange(1):stepSize:Xrange(2), Yrange(1):stepSize:Yrange(2));
YY = flipud(YY);

%Parzen parameters and function handle
pf1 = @(C1,C2) (1/N)*(1/((2*pi)*Sigma^2)).*...
         exp(-( (C1(1)-C2(1))^2+ (C1(2)-C2(2))^2)/(2*Sigma^2));

PPDF1 = zeros(size(XX));    

%Populate coordinate surface
[R C] = size(PPDF1);
NN = length(D);
for c=1:C
   for r=1:R 
       for d=1:N 
            PPDF1(r,c) = PPDF1(r,c) + ...
                pf1([XX(1,c) YY(r,1)],[D(d,1) D(d,2)]); 
       end
   end
end


%Normalize data
m1 = max(PPDF1(:));
PPDF1 = PPDF1 / m1;

%Set up visualization
set(0,'defaulttextinterpreter','latex','DefaultAxesFontSize',20)
fig = figure(1);clf
stem3(D(:,1),D(:,2),zeros(N,1),'b.');
hold on;

%Add PDF estimates to figure
s1 = surfc(XX,YY,PPDF1);shading interp;alpha(s1,'color');
sub1=gca;
view(2)
axis([Xrange(1) Xrange(2) Yrange(1) Yrange(2)])

注意,这种可视化实际上是3维的:

Note, this visualization is actually 3-dimensional:

这篇关于通过点聚类着色的等高线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆