subplots destroys the axis properties
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi all,
I have to create a figure with a specific layout of subplots, but when I call the subplot for the second time all the axis properties are destroyed, why? Here an example:
subhpos(1,:)=[0.0434 0.0339 0.9362 0.9126];
subhpos(2,:)=[0.8189 0.8801 0.1505 0.1017];
figure
set(gcf,'Position',[ 9 49 784 767]);
subh(1)=subplot(1,2,1);
set(subh(1),'Position',subhpos(1,:))
subh(2)=subplot(1,2,2)
set(subh(2),'Position',subhpos(2,:));
subplot(1,2,1)
thanks
cheers
댓글 수: 1
채택된 답변
dpb
2014년 7월 10일
Per the doc, if you overwrite the area of a subplot, it deletes the existing one and creates a new one. AFAIK there's no way to avoid this behavior. There's an example of an overlaying axes with subplot() in the documentation; note that it avoids this by specifying that axes with axes, not another subplot.
You can probably get by with yours if you only refer to the two axes with the saved handles once they're created.
댓글 수: 0
추가 답변 (1개)
Joseph Cheng
2014년 7월 10일
well what you can try is this by moving the setting of the axis properties at the end such that you do not overwrite them.
figure
subhpos(1,:)=[0.0434 0.0339 0.9362 0.9126];
subhpos(2,:)=[0.8189 0.8801 0.1505 0.1017];
x=[60:20:260]; %set x axis ticks
y=rand(11); %get something to plot
subh(1)=subplot(2,1,2); %setup subplot1
plot(x,y,'-.'); %plot subplot1
xlim([60 260]) %setup some x axis
set(gcf,'Position',[ 9 49 784 767]);
y2 = 10*y.^2; %make something up for subplot2
subh(2)=subplot(2,1,1); %make subplot2
plot(x,10*y,'-.'); %plot subplot2
xlim([60 260]) %setup some x axis
set(subh(2),'Position',subhpos(2,:))
set(subh(1),'Position',subhpos(1,:));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!