subplots destroys the axis properties
1 次查看(过去 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!