Add contours to scatter3 plot
11 views (last 30 days)
Show older comments
Hi,
Is there a way to add contours on the walls of this kind of plot? The points are projected onto the walls.
x = mvnrnd(1, 3, 100);
y = mvnrnd(2, 3, 100);
z = mvnrnd(3, 3, 100);
scatter3 (x, y, z, 'filled')
hold on
scatter3 (0*x+ max(x), y, z, '.')
hold on
scatter3 (x, 0*y+max(y), z, '.')
hold on
scatter3 (x, y, 0*z+min(z), '.')
hold off
rotate3d on
Best regards, Alex
0 Comments
Accepted Answer
Tim Berk
on 19 Sep 2017
Contours can be drawn on a 2D slice in a 3D figure using contourslice.
I'm not sure what the contours are that you want to plot. I just specify some random contour in variable V.
Note that you are not projecting points at the wall, but at the location of the maximum. I fixed this by actually plotting at the limits.
x = mvnrnd(1, 3, 100);
y = mvnrnd(2, 3, 100);
z = mvnrnd(3, 3, 100);
scatter3 (x, y, z, 'filled')
hold on
xl = xlim;
yl = ylim;
zl = zlim;
xlim(xl); ylim(yl); zlim(zl); % fix the limits for if we rotate
scatter3 (0*x+xl(2), y, z, '.')
scatter3 (x, 0*y+yl(2), z, '.')
scatter3 (x, y, 0*z+zl(1), '.')
rotate3d on
[X,Y,Z]=meshgrid(round(xl(1)):round(xl(2)),round(yl(1)):round(yl(2)),round(zl(1)):round(zl(2)));
V = X.^2+Y.^2+Z.^2;
contourslice(X,Y,Z,V,xl(2),yl(2),[zl(1) zl(2)])
hold off
1 Comment
More Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!