14

一連の軸が事前に配置された 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')

…ああ、そして…

代替テキスト

MATLAB は、すべてを元の座標軸空間に押し込みます。これを回避する方法はありますか?

4

1 に答える 1

8

編集

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

代替テキスト

于 2010-08-30T17:12:11.990 に答える