Change legend width after reisze of legend line length

조회 수: 5 (최근 30일)
Simon
Simon 2017년 10월 6일
답변: David J. Mack 2017년 10월 6일
Hello Matlab community,
I'm struggeling with formatting of a legend in a Matlab Plot. As the line of the legend is rather long in default I changed it with the help of icon objects.
l=legend('P','Location','southeast','Orientation','vertical');
icons(1).Position = [0.1 p1(2) 0.01 ];
icons(1).Units='normalized'
icons(2).XData = [0.05 0.01];
This works and the legend line length gets sized. The following problem is that the width of the legend remains constant and does not resize. I tried to manipulate the position object of the legend but the width seems to have an internal lower limit.
set(l,'Unit','normalized','Position',[0.0,0.0,0.01,0.2]);
I can increase the size but not decrease. I tried reverse engineering via Matlab Plot Browser and here the same problem occurs. When I try to decrease the width the box moves to the left and has same size.
This is what it looks like (the legend is flushed with another script, but disabling this one leads to the same problem):
I would appreciate some hints where to further search in order to resize the legend size.
Thanks in advance Simon

답변 (1개)

David J. Mack
David J. Mack 2017년 10월 6일
Hey Simon,
this is an issue which pops up regularly, since the customization options of legends are currentyl (when I last checked) not layed out to change the size. Out of frustration I wrote a small helper function once to change the size of the legend ( resizeLegend ). Maybe this helps. Greetings, David

카테고리

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