Subplots: Plots do not have all their properties
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone! I have the following problem: I have code, which takes two saved figures and puts them into a new figure, but it does not copy all the properties of the original figures - including axis label and the titels. This is the code I am using at the moment.
%%Merge figures into subplots
fig1=hgload(rel_save_path_0);
fig2=hgload(rel_save_path_1);
save_path_4 = strcat('/Plots_Fig/','SubplotOverview','.fig');
% Prepare subplots
figure
h(1)=subplot(1,2,1);
h(2)=subplot(1,2,2);
% Paste figures on the subplots
copyobj(allchild(get(fig1,'CurrentAxes')),h(1));
copyobj(allchild(get(fig2,'CurrentAxes')),h(2));
xlim([0,700]);
ylim([-2,9]);
% Add legends
title('TEST');
l(1)=legend(h(1),'spec1','spec2','spec3','spec4','spec5','spec6','mean');
l(2)=legend(h(2),'boundary','mean');
print2eps('Subplot');
% saveas(fig_subplots_evSing,'Subplot','fig');
saveas(gcf,[pwd save_path_4]);
2 个评论
dpb
2017-10-9
Known limitations in copyobj of anything that is context-sensitive won't be copied.
We can't tell what might be going on and if is way to work around without your specific figures -- only need one presuming same symptoms for both; attach one of the files via the paperclip button.
Also, NB: that hgload has been deprecated; use openfig instead--doubt it will solve your issues, but never hurts to try.
采纳的回答
dpb
2017-10-10
Maybe be "more better" ways; I've not much practical experience with copyobj, but the following seems to get you where you want to be...
hF=figure; % make new figure, save handle
for i=1:2,hSP(i)=subplot(2,1,i);end % make subplot axes
posn=get(hSP,'position'); % and save positions for later
delete(hSP) % clear those axes; we're going to overwrite
hNew{1}=copyobj(hCh,hF); % copy the two figures onto new one
hNew{2}=copyobj(hCh,hF); % don't worry about overlaying for moment
for i=1:2
set(hNew{i}(2),'position',posn{i}) % now set the subplot sizes we found before
set(hNew{i}(1),'fontsize',7) % make legend text small enough...
end
There may be some magical way to get the rest of the pieces onto the new,existing subplot axes, but the copying of the axes onto the figure parent grabs all the pertinent pieces auotmagically this way; just then resize to simulate what subplot would have done.
NB: there are callbacks and all in these figures; those don't get save/copied over. You'd have to reestablish those connections if want the new axes to have same abilities as original in that regard.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178587/image.jpeg)
0 个评论
更多回答(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!