subplots destroys the axis properties

11 ビュー (過去 30 日間)
pietro
pietro 2014 年 7 月 10 日
回答済み: Joseph Cheng 2014 年 7 月 10 日
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 件のコメント
Sara
Sara 2014 年 7 月 10 日
Try moving the set of the first subplot after you create the second subplot. Is that what you want?

サインインしてコメントする。

採用された回答

dpb
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.

その他の回答 (1 件)

Joseph Cheng
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,:));

Community Treasure Hunt

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

Start Hunting!

Translated by