Why does legend('Position') overwrite strings?
이전 댓글 표시
When I try to reset the position of a legend with a legend('Position',...) command, the legend string changes to "Position". In contrast, legend('Location',...) works as I expect (but does not give the same level of control). Here is a minimal working example:
x=0:0.02:1;
y=x.^2;
z=x.^3;
f=figure;
hold on;
plot(x,y,'displayname','x^2');
plot(x,z,'displayname','x^3');
legend('show')
legend('Location','Best'); % This works as expected.
% But if I use the next line instead of setting Location,
% I just get the word 'Position' in the legend
% (and the legend seems to be located at 0,0).
% legend('Position',[0.5 0.5 0.2 0.2]);
It appears that a work-around is to use:
hl=legend('show');
legend(hl.String,'Position',[0.5 0.5 0.2 0.2]);
but I am curious why the simpler version fails. What am I doing wrong with legend('Position',...) ?
Thanks.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!