Put existing 3D figures on subplot
56 次查看(过去 30 天)
显示 更早的评论
I have a couple figures already existing in my program but want to add them together to a subplot. e.g., put fig 1 and fig 5 on a subplot. I found some code and modified it slightly:
%% Original 3D Plot
[X,Y,Z] = peaks;
plot = surf(X,Y,Z);
%% Copy plot to subplots
f = figure;
s1 = subplot(1,3,1);
s2 = subplot(1,3,2);
s3 = subplot(1,3,3);
copyobj(plot,s1);
copyobj(plot,s2);
copyobj(plot,s3);
%% Set different viewing angle for each subplot
view(s1,0,90); title(s1,'view(0,90)');
view(s2,90,0); title(s2,'view(90,0)');
view(s3,0,0); title(s3,'view(0,0)');
My problem is it loses the third dim and plots everything 2D.
2 个评论
回答(1 个)
Md Modassir Firdaus
2022-12-30
Hi everyone
You can try this code to create single figure having subplots. Here single plot is in subplot becouse it does not saved figure 1. First save the created plot then comment "savefig".
clc;
close all;
clear;
%%
z1=peaks;
z2=z1+randn(size(z1))/5;
figure(1)
surf(z1) %creating first figure
savefig('PeaksFile1.fig') % save the figure once then comment it
%%%%
figure(2)
surf(z2,'FaceColor','r') %creating second figure
savefig('PeaksFile2.fig')% save the figure once then comment it
%% Loading saved above figure
f1=hgload('PeaksFile1.fig');
f2=hgload('PeaksFile2.fig');
%% creating subplot
figure(3)
h(1)=subplot(1,2,1);
view(3)
grid on
h(2)=subplot(1,2,2);
view(3)
grid on
%%
copyobj(allchild(get(f1,'CurrentAxes')),h(1));
copyobj(allchild(get(f2,'CurrentAxes')),h(2));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!