M2014b+ graphics, changing legend orientation ex post

조회 수: 1 (최근 30일)
Jakub Rysanek
Jakub Rysanek 2016년 10월 26일
댓글: Jakub Rysanek 2016년 10월 26일
Under new Matlab graphics, changing the legend orientation does not work well if the legend was created with all 4 output arguments, i.e. [LEGH,OBJH,OUTH,OUTM] = legend(...). On the other hand, the behavior seems to be fine when the legend was created using only LEGH = legend(...). Specifically I have encountered the problem that the legend shape gets adjusted but the legend contents stay according to the original legend orientation which makes my figures look unacceptable.
%%Works properly
figure;
hold on;
p1=plot(1:10);
p2=plot(10:-1:1);
lghandle=legend([p1;p2],{'Line 1','Line 2'});
set(lghandle,'orientation','horizontal');
%%Does not work properly
figure;
hold on;
p1=plot(1:10);
p2=plot(10:-1:1);
[lghandle,l2,l3,l4]=legend([p1;p2],{'Line 1','Line 2'});
set(lghandle,'orientation','horizontal');
Is this a bug?

답변 (1개)

Adam
Adam 2016년 10월 26일
Well, that help for that particular overload does state:
"Note: This syntax is not recommended. It creates a legend that does not support all graphics features. Instead, use the lgd = legend(__) syntax to return the legend object and set Legend Properties."
so I guess that would explain any odd behaviour.
  댓글 수: 3
Adam
Adam 2016년 10월 26일
편집: Adam 2016년 10월 26일
I haven't really used legend, but I assume now that it is a graphics object in its own right that the one returned argument, 'lgd' is a legend object which you can interrogate to get various properties out of so I assume these would be included in there.
Jakub Rysanek
Jakub Rysanek 2016년 10월 26일
...the 'itemText' property which used to work in earlier versions is now empty and the usual sniffing point, the 'children' property, does not contain any information either. I am working with a simple line plot()

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by