Add contours to scatter3 plot

조회 수: 11 (최근 30일)
Alex Kurek
Alex Kurek 2017년 9월 16일
편집: Alex Kurek 2017년 9월 19일
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

채택된 답변

Tim Berk
Tim Berk 2017년 9월 19일
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
Alex Kurek
Alex Kurek 2017년 9월 19일
편집: Alex Kurek 2017년 9월 19일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by