How to extract subplots from a saved figure to copy say, subplot(1,2,1) into new figure

조회 수: 97 (최근 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

답변 (3개)

Akshay Kumar
Akshay Kumar 2018년 8월 8일
If you are looking for code to do it, use this Click here

Walter Roberson
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
Jorge Rivé
Jorge Rivé 2016년 9월 12일
I'm with you for openfig and findobj...then I'm lost, ;-). not sure what to do with this (subplot's in original figure are actually (2,1,1) and (2,1,2).
Axes with properties:
XLim: [0 1]
YLim: [0 1]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [0.1300 0.1100 0.7750 0.8150]
Units: 'normalized'
Show all properties
ALim: [0 1]
ALimMode: 'auto'
ActivePositionProperty: 'outerposition'
AmbientLightColor: [1 1 1]
BeingDeleted: 'off'
Box: 'off'
BoxStyle: 'back'
BusyAction: 'queue'
ButtonDownFcn: ''
CLim: [0 1]
CLimMode: 'auto'
CameraPosition: [0.5000 0.5000 9.1603]
CameraPositionMode: 'auto'
CameraTarget: [0.5000 0.5000 0.5000]
CameraTargetMode: 'auto'
CameraUpVector: [0 1 0]
Walter Roberson
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
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
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
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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by