Subplots: Plots do not have all their properties

조회 수: 1 (최근 30일)
Peter Bu
Peter Bu 2017년 10월 9일
답변: dpb 2017년 10월 10일
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
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.
Peter Bu
Peter Bu 2017년 10월 10일
I added it.

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by