How to extract subplots from a saved figure to copy say, subplot(1,2,1) into new figure
35 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have multiple figures that consist 2 subplots. I want to load the figures, extract each subplot(1,2,1), for example, and put in another figure (of subplots), and each subplot(1,2,2) into another figure (of subplots as well). I don't know how to access the individual subplots within a plot from a loaded figure.
Thanks
0 comentarios
Respuestas (3)
Walter Roberson
el 12 de Sept. de 2016
The axes created for subplots do not have any property that indicates which subplot combination they were created for. What you will need to do is openfig() to get the handle of the fig, findobj() with 'type', 'axes' to find both axes, then take the one for which the position X coordinate is greater.
2 comentarios
Walter Roberson
el 13 de Sept. de 2016
fig = openfig('whatever.fig');
ax = findobj(fig, 'type', 'axes'); %should return a vector of length 2
if length(ax) < 2
error('there was only %d visible axes in the figure', length(ax) );
end
axpos = [ax(1).Position; ax(2).Position];
if axpos(1,1) > axpos(2,1)
disp('first axes is to the right of second')
elseif axpos(1,2) < axpos(2,1)
disp('first axes is to the left of second');
else
disp('axes are lined up horizontally');
end
if axpos(1,2) > axpos(2,2)
disp('first axes is above second')
elseif axpos(2,2) < axpos(2,2)
disp('first axes is below second');
else
disp('axes are lined up vertically');
end
Steven Lord
el 12 de Sept. de 2016
If you intend the subplot axes in the destination figure to be in the same sized tiling as in the source figure (so you want subplot axes (m, n, p) from the source figure to be in location (m, n, p) in the destination figure) then once you have their handles use the copyobj function to copy them from the source figure to the destination figure.
If you want the axes in the destination figure to be a different size than the axes in the source figure but you know how large you want the axes to be in the destination, use copyobj to copy the axes then change the Position property of the copied axes.
3 comentarios
x!lef
el 11 de Abr. de 2017
Did you find a satifying solution for your problem? If so, could you please post it here? I'm facing the same problem. Thank you and all the best Felix
Walter Roberson
el 11 de Abr. de 2017
As I explained above, subplot() does not record its arguments inside the axes, so the only way to figure out which subplot is which is to compare the Position properties of the axes to find the one you want.
Ver también
Categorías
Más información sobre Subplots 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!