Combining existing figures, each in its own tile

104 visualizaciones (últimos 30 días)
Chris Koen
Chris Koen el 22 de Sept. de 2022
Comentada: Ahmed Mahfouz el 27 de Feb. de 2024
I have three figures, each in a .fig file. I want
to combine these, in a subplot-type layout
(i.e. each in a separate tile). Is there a way of doing
this retaining the properties of the figures (e.g. fonts,
axis scales, axis inversions, etc?

Respuesta aceptada

dpb
dpb el 22 de Sept. de 2022
It's pretty easy if just copying an axes and its content to a new figure; when it's a new axes that's been created with either subplot or nexttile, then have to select the components under the axes and put them in the new one.
I tried with tiledlayout for the first one after
hF=openfig('yourfirstsaved.fig');
TLO=tiledlayout(3,1);
nexttile
copyobj(copyobj(hF.Children,get(hF.Children,'Type')),TLO)
worked as desired; however, after
nexttile
I couldn't figure out any way to point the target of a similar copyobj to the TLO handle that directed it to the next tile successfully; by default it kept putting new copies on top of the same first tiled axis.
Trying
copyobj(copyobj(hF1.Children,get(hF1.Children,'Type')),gca)
resulted in
Error using copyobj
Axes cannot be a child of Axes.
since then the target is the axes handle so trying to shortcircuit to copy the whole axes, etc., can't work because there's already an axes.
So, then it becomes more work to pick the sub-pieces and some pieces may not get copied depending on the content in the figure.
  3 comentarios
dpb
dpb el 24 de Sept. de 2022
Editada: dpb el 24 de Sept. de 2022
I don't see any alternative, no. But, you should be able to use the expanded search capabilities of findobj to return everything from the figure from the axes down...now whether that will then reproduce the figure in all its glory or not depends on what all is in the figure -- legends may be an issue, for example.
Ahmed Mahfouz
Ahmed Mahfouz el 27 de Feb. de 2024
I just had the same problem and I could work out a way to copy the axes into tiles other than the first one.
Adding to what @dpb suggested, you can try the following lines to avoid stacking the axes on top of each other in the first tile:
listOfFigNames = {'fig1.fig', 'fig2.fig', 'fig3.fig'};
nFigs = length(listOfFigNames);
tl = tiledlayout(nFigs, 1);
for i =1:nFigs
hF_temp = openfig(listOfFigNames{i});
ax_temp = copyobj(copyobj(hF_temp.Children, get(hF_temp.Children,'Type')), tl);
ax_temp(1).Layout.Tile = i;
end

Iniciar sesión para comentar.

Más respuestas (1)

Karl_469
Karl_469 el 2 de Nov. de 2023

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by