How do I rotate a 3D scatterplot automatically around the x-axis?
22 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Deepak Meena
on 27 Jan 2021
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
0 Comments
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!