Azzera filtri
Azzera filtri

Add contours to scatter3 plot

5 visualizzazioni (ultimi 30 giorni)
Alex Kurek
Alex Kurek il 16 Set 2017
Modificato: Alex Kurek il 19 Set 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

Risposta accettata

Tim Berk
Tim Berk il 19 Set 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 Commento
Alex Kurek
Alex Kurek il 19 Set 2017
Modificato: Alex Kurek il 19 Set 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by