在轴外添加图例,而无需在MATLAB中重新缩放 [英] Add legend outside of axes without rescaling in MATLAB

查看:83
本文介绍了在轴外添加图例,而无需在MATLAB中重新缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中有一个GUI,其中预先放置了一组轴.我正在使用图例的location属性将其放置在轴的右侧.但是,通过这样做,轴将重新缩放,以使轴+轴角占据轴的原始宽度.有什么办法可以避免调整大小?

I've got a GUI in MATLAB with a set of axes pre-placed. I'm using the location property of the legend to place it to the right hand side of the axes. However, by doing this the axes get re-scaled so that the axes+legend take up the original width of the axes. Is there any way to circumvent the re-size?

示例:

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)

到目前为止,我得到了:

So far I get:

地点图例:

legend('sin(x)','location','eastoutside')

... aaaa和...

...aaaaand...

MATLAB将其全部压缩到原始轴空间中.可以解决这个问题吗?

MATLAB squishes it all into the original axes space. Any way around this?

推荐答案

编辑

%# 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)])

这篇关于在轴外添加图例,而无需在MATLAB中重新缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆