Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MATLAB中添加轴外的图例,无需重新缩放_Matlab_Plot_Legend_Axes - Fatal编程技术网

在MATLAB中添加轴外的图例,无需重新缩放

在MATLAB中添加轴外的图例,无需重新缩放,matlab,plot,legend,axes,Matlab,Plot,Legend,Axes,我在MATLAB中有一个GUI,预先放置了一组轴。我使用图例的location属性将其放置在轴的右侧。但是,通过执行此操作,轴将重新缩放,以便轴+图例占据轴的原始宽度。有没有办法避免重新调整尺寸 例如: 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) 到目前为止,我得到

我在MATLAB中有一个GUI,预先放置了一组轴。我使用图例的location属性将其放置在轴的右侧。但是,通过执行此操作,轴将重新缩放,以便轴+图例占据轴的原始宽度。有没有办法避免重新调整尺寸

例如:

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')
…AAAA和

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

是的,我知道这是自动完成的,但我有三组垂直堆叠的轴,它们从同时采集中绘制单独的数据集。标签是日期戳,所以我只需要一个图例。问题是,当我只将图例添加到中心图时,其他两个不再对齐。我在GUI的末尾有一块空白,有足够的空间放图例,我想把它放在那里。您可以随时手动设置它的
位置
属性以适合您的需要layout@Doresoom:我用上面的想法加了一个例子。是的,我也开始工作了——你建议编辑position属性,这让我走上了正确的轨道。这意味着原来问题的答案是“否”,对吗?