Add contours to scatter3 plot

11 views (last 30 days)
Alex Kurek
Alex Kurek on 16 Sep 2017
Edited: Alex Kurek on 19 Sep 2017
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

Accepted Answer

Tim Berk
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
Alex Kurek
Alex Kurek on 19 Sep 2017
Edited: Alex Kurek on 19 Sep 2017
Thanky you. The contours are a bit displaced. This is the way to correct it:
V = (X-1).^2 + (Y-2).^2 + (Z-3).^2;
Best regards, Alex

Sign in to comment.

More Answers (0)

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!