gpt4 book ai didi

matlab - 在 MATLAB 中不重新缩放的情况下在轴外添加图例

转载 作者:太空宇宙 更新时间:2023-11-03 19:11:20 25 4
gpt4 key购买 nike

我在 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)

到目前为止我得到:

alt text

放置图例:

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

...aaaaand...

alt text

MATLAB 将其全部压缩到原始坐标区空间中。有什么办法解决这个问题吗?

最佳答案

编辑

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

alt text

关于matlab - 在 MATLAB 中不重新缩放的情况下在轴外添加图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3602571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com