简体   繁体   中英

How to add 2d points to a 3d scatterplot

I have a 3d scatterplot, and would like to display the 2d points onto the 3 planes (x,y), (x,z), and (y,z), as if they were shadows of the 3d data projected onto the planes. The left-hand figure is an example:

http://www.doka.ch/Excel3Dscatterplot.htm

Can this be achieved in R or Matlab? I have searched for code that can do this, but have not succeeded.

Yes, for any 3D point

P = [x y z]

you can create the 3 shadows by creating 3 new points

p1 = [0 y z]
p2 = [x 0 z]
p3 = [x y 0]

So, in MATLAB, if you have a point cloud,

P_cloud = [...
    x1 y1 z1
    x2 y2 z2
    x3 y3 z3
    ...
];

Just plot

P_cloud_YZ = [...
    0 y1 z1
    0 y2 z2
    0 y3 z3
    ...
]; 

P_cloud_XZ = [...
    x1 0 z1
    x2 0 z2
    x3 0 z3
    ...
];  


P_cloud_XY = [...
    x1 y1 0
    x2 y2 0
    x3 y3 0
    ...
];  

or, of course, re-use the same data

[P_cloud(:, [2 3]) zeros(size(P,1),1)]
[P_cloud(:, [1 3]) zeros(size(P,1),1)]
[P_cloud(:, [1 2]) zeros(size(P,1),1)]

After doing something like this:

figure
[X,Y,Z] = sphere(16);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
scatter3(x,y,z)

you can just use the same figure and add some other plots to that:

hold on;
plot3(x,y,min(z)*ones(size(x)),'r+');
plot3(min(x)*ones(size(x)),y,z,'g+');
plot3(x,min(y)*ones(size(x)),z,'k+');

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM