How can i rotate a 2d line graph to 3d graph?

3 次查看(过去 30 天)
Hello friends, i have a line plot (x-axis and y-axis), i want to rotate it 360 degree about the origin and create it like 3D graph. Kindly help me.
  4 个评论

请先登录,再进行评论。

回答(1 个)

Jacob Mathew
Jacob Mathew 2024-12-4
Hi Aravindan,
I assume you want to show the plot in 3 dimension. You can use the plot3 method to plot the points in 3 dimensional space. You can then change the perspective by manually clicking and dragging on the graph. Or you can use the view method within a for loop to have an animated view from a 360 degree perspective. Here is an example code:
% Vertical parabola in 3D space
x = linspace(-5, 5, 100);
y = zeros(size(x));
z = x.^2;
% Create the 3D plot
figure;
h = plot3(x, y, z, 'LineWidth', 2);
axis equal;
grid on;
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Parabola Animation');
% Animation loop
% NOTE: The animation does not render if you run here
for angle = 1:360
% Rotate the plot around the axis passing through the parabola's minimum
% Here, the axis is the y-axis, so we rotate around it
view([angle, 30]);
drawnow;
pause(0.05); % Adjust the pause for speed of rotation
end
You can refer to the documentation for plot3 and view functions in the links below:

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by