Change legend width after reisze of legend line length

11 views (last 30 days)
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

Answers (1)

David J. Mack
David J. Mack on 6 Oct 2017
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

Community Treasure Hunt

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

Start Hunting!