根据点的密度对3D散点图的颜色点进行编码 [英] Color code points of 3D scatter plot according to density of points

查看:144
本文介绍了根据点的密度对3D散点图的颜色点进行编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在xyz球体中有一个点的3D散点图.我想知道是否有一种方法可以根据数据的密度对散点图进行颜色映射/色相绘制.基本上,散点图中具有最密集聚类数据点的部分将为暗红色,半密集聚类数据点将为中红色,而稀疏聚类数据点将为浅红色.

I have a 3D scatter plot of points in the xyz-sphere. I was wondering if there is a way to colormap/hue the scatter plot based on the density of the data. Basically, the parts of the scatter plot with the most densely clustered data points would be dark red, semi densely clustered data points would be medium red, and sparsely clustered data points would be light red.

这是我一直在想的方式,但是(希望)可能会有一个更简单的函数或命令来做到这一点.

This is the way that I was thinking of, but (hopefully) there might be a simpler function or command to do this.

设置散点中的数据点必须被包围的阈值:

Set a threshold that a data point in the scatter has to be surrounded by:

[> =半径1的球体内的10个其他点将被染成深红色,

[ >= 10 other points within a sphere of radius 1 to be colored dark red,

[半径1的球体内的5-9个其他点将变为红色,而

[ 5-9 other points within a sphere of radius 1 to be colored medium red, and

[半径为1的球体中的0-4将变为浅红色.

[ 0-4 within a sphere of radius 1 to be colored light red.

当然,我希望有一种更简单的方法可以在颜色图中涉及3种以上的颜色,因此,如果有人对如何编码有任何想法,我将非常感谢您的帮助!非常感谢.

Of course, I'm hoping there is a simpler way to do this that involves more than 3 colors in the color map, so if anyone has any ideas how to code this, I'd appreciate the help! Thank you so much.

这是我的数组的一个片段:

Here's a snippet of my array:

184    115   3915
185    115   3916
185    115   1205
186    115   4094
187    115   2237
192    115   1519
193    115   1327
201    115   1170
240    115   2946
241    115   1332
 54    116   1244
 58    116   3650
 59    116   3984
 60    116   1631
 61    116   1198
 61    116   1194
 62    116   1189
 65    116   1185
186    116   3669
188    116   3986
189    116   2027
197    116   1200
201    116   1254
226    116   3752
227    116   1457
242    116   1405
 54    117   1191
 54    117   1305
 56    117   1177
 58    117   1169
 61    117   1367
 62    117   1428
 62    117   1434
 62    117   1435
 63    117   1422
198    117   1197
229    117   1312
230    117   1179
243    117   1272
 55    118   1236
 56    118   1166
 61    118   1191
 65    118   1755
 57    119   1213
 57    119   1176
 58    119   1253
 62    119   1365
 62    119   1331
 63    119   1457
 63    119   1251
 66    119   1842
 66    119   1468
 59    120   1489
 59    120   1387
 60    120   1218
 60    120   1224
 61    120   1214
 61    120   1440
 62    120   1198
 64    120   1240
205    120   3601
205    120   1168
206    120   3727
207    120   4089
208    120   2128
208    120   1160
 56    121   1293
 57    121   1183
 59    121   1371
 59    121   1347
 61    121   1314
 64    121   1346
207    121   3562
208    121   3845
209    121   3534
210    121   1201
210    121   1405
 83    122   1794
206    122   1259
207    122   1161
 83    123   3550

推荐答案

在我的方法中,我使用阈值因子T来确定在计算每个单个点的距离时要考虑的其他点数. T = 1表示每个点到所有其他点的平均距离,T = 0.01表示每个点到其他点的最近1%的平均距离.

In my approach I'm using a threshold factor T to determine how many other points are considered in the calculation of distances for each individual point. T = 1 means for every point the average distance to all other points is calculated, T = 0.01 means for every point the average distance to the closest 1% of the the other points is calculated.

figure

%// example data
[X,Y,Z] = sphere(15);
x = [0.1*X(:); 0.4*X(:); 0.7*X(:)];
y = [0.2*Y(:); 0.5*Y(:); 0.8*Y(:)];
z = [0.3*Z(:); 0.6*Z(:); 0.9*Z(:)];
D = [x(:), y(:), z(:)];
N = numel(x);

%// calculation of color vector
[n,m] = ndgrid(1:N,1:N);
%// euclidian distance of each point to every other point
X = arrayfun(@(a,b) sum( (D(a,:) - D(b,:)).^2 ), n, m);

%% subplot 1
%// threshold factor
T = 0.01;

%// sort distances of points
Y = sort(X,2);
%// calculate average distance of the closest T% of all points
Z = mean(Y(:,2:ceil(N*T)),2);

%// plot
subplot(121)
scatter3(x,y,z,20,Z,'filled');
title('T = 0.01')
colormap
colorbar

%% subplot 2
%// threshold factor
T = 1;

Y = sort(X,2);
Z = mean(Y(:,2:ceil(N*T)),2);

%// plot
subplot(122)
scatter3(x,y,z,20,Z,'filled');
title('T = 1')
colormap
colorbar

这篇关于根据点的密度对3D散点图的颜色点进行编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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