How to extract subplots from a saved figure to copy say, subplot(1,2,1) into new figure
조회 수: 35 (최근 30일)
이전 댓글 표시
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
답변 (3개)
Walter Roberson
2016년 9월 12일
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
Walter Roberson
2016년 9월 13일
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
2016년 9월 12일
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
x!lef
2017년 4월 11일
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
2017년 4월 11일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!