添加轴的传说之外没有MATLAB重新调整
题
我有在MATLAB与一组轴的GUI预先放置的。我使用的是传说中的位置属性,其放置在轴的右边。然而,这样做的轴得到重新缩放,使得轴+传奇占用轴的原始宽度。有什么办法来规避调整大小?
示例:
x=0:.1:10;
y=sin(x);
figure
pos=get(gca,'position');
pos(3)=.5; %#re-size axes to leave room for legend
set(gca,'position',pos)
plot(x,y)
到目前为止,我得到:
放置说明:
legend('sin(x)','location','eastoutside')
... ... aaaaand
MATLAB squishes所有到原来的轴的空间。解决此任何方式?
解决方案
修改强>
%# create three axes with custom position
x=0:.1:10;
y=sin(x);
hAx1 = axes('Position',[0.05 0.05 0.7 0.2]); plot(hAx1, x,y)
hAx2 = axes('Position',[0.05 0.4 0.7 0.2]); plot(hAx2, x,y)
hAx3 = axes('Position',[0.05 0.75 0.7 0.2]); plot(hAx3, x,y)
%# add legend to middle one
h = legend(hAx2, 'sin(x)'); pos = get(h,'position');
set(h, 'position',[0.8 0.5 pos(3:4)])
不隶属于 StackOverflow