Why does legend('Position') overwrite strings?
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!