Reputation: 11
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:
Can this be achieved in R or Matlab? I have searched for code that can do this, but have not succeeded.
Upvotes: 1
Views: 4622
Reputation: 6424
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+');
Upvotes: 3
Reputation: 38032
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)]
Upvotes: 4