Legend appears at wrong place using GUIDE

I'm adding legends to my graphs in a programmatical GUI and I would like to control the size and position. When I use 'location', the legend shows up exactly where I told it to, but when I use 'position', it shows up in the bottom left corner of the figure/parent, no matter what values I fill in for position.
I added a simplified version of my work below.
f = figure;
tgroup = uitabgroup('Parent',f);
tab = uitab('Parent', tgroup);
ax1 = axes('Parent',tab);
plot(ax1,X,Y);
legend(ax1,'show',...
'parent','tab',...
'position',[0.5,0.5,0.1,0.02]);

Answers (1)

Eleonora - when I try to run your above code, I observe an error with legend due to the parent property. Is something new (post R2014)? Or, is it something that you have added and if so, what does it mean to you?
Note that if I remove this "property" I do see the legend appear in the bottom left corner as indicated by the position that you have set. But if I change it to say
[0.5,100.5,0.1,0.02]
then the legend moves accordingly.

3 Comments

Geoff, thank you for your answer.
I am currently working with 2015b 32 bit.
I added the parent because I thought that was the problem, without the parent property in the legend handle I get the exact same problem. I just tried it again - removing the parent property - and again the legend appears in the bottom left corner. Do you think it has to do with my Matlab version?
The way legend() works is complicated and changed as of R2014b. You effectively can no longer set its Parent property. legend() formerly created an axes() whose properties could be controlled, but now it creates a legend object with a number of hidden (and sometimes redundant) properties.
So concluded, I can not set the legend where I want in 2015b?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!