How to plot two .fig file as subplots in a new figure window ?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to create a single figure window conataining both the .fig files as subplots. Help is deeply appreciated.
0 commentaires
Réponse acceptée
Jonas
le 12 Déc 2022
h(1) = openfig('fog.fig','invisible');
ax(1)=gca;
h(2) = openfig('snow.fig','invisible');
ax(2)=gca;
N=numel(h);
figure;
for i=1:N
% create and get handle to the subplot axes
s(i) = subplot(N,1,i);
% get handle to all the children in the figure
aux=get(ax(i),'children');
for j=1:size(aux)
fig(i) = aux(j);
copyobj(fig(i),s(i));
hold on
end
% copy children to new parent axes i.e. the subplot axes
xlab = get(get(ax(i),'xlabel'),'string');
xlabFontSize= get(get(ax(i),'xlabel'),'FontSize');
xlabInterpreter = get(get(ax(i),'xlabel'),'Interpreter');
ylab = get(get(ax(i),'ylabel'),'string');
ylabFontSize = get(get(ax(i),'ylabel'),'FontSize');
ylabInterpreter = get(get(ax(i),'ylabel'),'Interpreter');
tit = get(get(ax(i),'title'),'string');
titFontSize = get(get(ax(i),'title'),'FontSize');
titInterpreter = get(get(ax(i),'title'),'Interpreter');
hasLegend=~isempty(findobj(h(i),'type','legend'));
if hasLegend
lgText = get(get(ax(i),'legend'),'string');
lgLocation = get(get(ax(i),'legend'),'Location');
end
xLimits = get(ax(i),'XLim');
yLimits = get(ax(i),'YLim');
xGrid = get(ax(i),'XGrid');
yGrid = get(ax(i),'YGrid');
ScaleX = get(ax(i),'Xscale');
ScaleY = get(ax(i),'Yscale');
TickX = get(ax(i),'Xtick');
TickY = get(ax(i),'Ytick');
TicklabelX = get(ax(i),'Xticklabel');
TicklabelY = get(ax(i),'Yticklabel');
set(gca, 'XScale', ScaleX, 'YScale', ScaleY, 'Xtick', TickX, 'Ytick',...
TickY, 'Xticklabel', TicklabelX, 'Yticklabel', TicklabelY,'XGrid',xGrid,'YGrid',yGrid);
xlabel(xlab,'FontSize',xlabFontSize,'Interpreter',xlabInterpreter);
ylabel(ylab,'FontSize',ylabFontSize,'Interpreter',ylabInterpreter);
title(tit,'FontSize',titFontSize,'Interpreter',titInterpreter);
xlim(xLimits);
ylim(yLimits);
if hasLegend
legend(lgText,'Location',lgLocation)
end
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!