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

24 次查看(过去 30 天)
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by