How do I plot multiple views of 3D plot in the same figure?

I have a 3D graphic with several plot objects in it. I want to show this graphic from several different angles, such that each view shows up as a subplot in the same figure. How do I accomplish this?

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2019년 10월 22일
You can start by creating a figure with three axes using "subplot". Then, plot each of your objects onto the first axes, while making sure to save each plot object with a function handle.
Next, using "copyobj",
<https://www.mathworks.com/help/matlab/creating_plots/copy-and-delete-graphics-objects.html#bt51tv3>
copy the multiple plot objects to a single new parent (i.e. your second axes), and repeat this step for your third axes.
Finally, change the camera angle on each of your axes using the "view" function:
<https://www.mathworks.com/help/matlab/ref/view.html>
To see all these steps implemented together, consider the example below:
%% Create figure with 3 subplots
f = figure('Units','normalized','OuterPosition',[0 .5 1 .5]);
ax1 = subplot(1,3,1);
ax2 = subplot(1,3,2);
ax3 = subplot(1,3,3);
%% Plot some surfaces on 1st subplot
[X,Y,Z] = peaks;
s = surf(ax1,X,Y,Z); hold(ax1,'on');
p = surf(ax1,X,Y,zeros(size(X))); hold(ax1,'off');
plotObjs = [s,p];
%% Copy plot objects to other 2 subplots
copyobj(plotObjs,ax2);
copyobj(plotObjs,ax3);
%% Set different viewing angle for each subplot
view(ax1,0,90); title(ax1,'view(0,90)');
view(ax2,90,0); title(ax2,'view(90,0)');
view(ax3,0,0); title(ax3,'view(0,0)');

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품

릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by