How do I rotate a 3D scatterplot automatically around the x-axis?

조회 수: 56 (최근 30일)
Pooja Khanna
Pooja Khanna 2021년 1월 15일
답변: Deepak Meena 2021년 1월 27일
I have generated a 3D scatterplot for my variables. I'd like to be able to rotate it around the x-axis, preferably in a continuous loop. Any help would be appreciated.

답변 (1개)

Deepak Meena
Deepak Meena 2021년 1월 27일
Hi Pooja,
From my understnading you want to rotate a 3d scatter plot programatically. For surface, line plot MATLAB have rotate which can rotate a figure about a particular direction and given degrees. But that doesn't work for the 3dScatter plot . But there is work around that :
1)Draw a 3d line plot of the corresponding scatter plot
2)Rotate that 3d line plot using the rotate function.
3)get the data from the line plot and draw the corresponding 3dScatterplot .
For ex#
figure
[X,Y,Z] = sphere(16);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.0*Y(:); 0.0*Y(:); Y(:)];
z = [0.0*Z(:); 0.0*Z(:); Z(:)];
scatter3(x,y,z);
This will plot this scatter plot :
Step 1:
when we draw the line plot of this scatter plot :
figure(2)
p = plot3(x,y,z);
Step 2:
Now we rotate this around z-axis by 25 degrees as:
direction = [0 0 1];
rotate(p,direction,25);
so we have :
Step 3:
Now we get the data from the rotated line plot and plot a scatter plot as follow:
x =p.XData;
y = p.YData;
z = p.ZData;
figure(2);
scatter3(x,y,z)
so we have :
To do this in continuous loop :
figure
[X,Y,Z] = sphere(16);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.0*Y(:); 0.0*Y(:); Y(:)];
z = [0.0*Z(:); 0.0*Z(:); Z(:)];
scatter3(x,y,z);
p = plot3(x,y,z);
for i=1:10
direction = [0 0 1];
rotate(p,direction,25);
x =p.XData;
y = p.YData;
z = p.ZData;
figure(2);
scatter3(x,y,z);
pause(2);
end
Hope this helps
Thanks

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by