我在 MATLAB 中有一个 GUI,其中预先放置了一组轴。我使用图例的位置属性将其放置在轴的右侧。但是,通过这样做,轴会重新缩放,以便轴+图例占据轴的原始宽度。有什么办法可以避免重新调整大小吗?
Example:
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')
……啊啊啊……
MATLAB 将其全部压缩到原始轴空间中。有什么办法解决这个问题吗?
EDIT
%# 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)])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)