How do I plot multiple views of 3D plot in the same figure?
72 views (last 30 days)
Show older comments
MathWorks Support Team
on 22 Oct 2019
Answered: MathWorks Support Team
on 22 Oct 2019
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?
Accepted Answer
MathWorks Support Team
on 22 Oct 2019
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 Comments
More Answers (0)
See Also
Categories
Find more on Axis Labels 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!