How can I optimize the 'position' of multiple legends as a function of font for automated figure generation?

1 view (last 30 days)
Hi there,
I am automating the production of four layered rose graphs across many cases and therefore I'm looking to automatically optimize the appearance of the legend. Each layer has it's own legend. The rose graph is first produced (using patch function) and saved as an image (with no legend). While I keep it's visibility off, I then set the paperposition to a new size catered to the size of the first legend. Then I generate the first legend in a for loop using the following code. I first check using a= get(leg1,'Position') to see what fraction of the paper the legend is taking up. If it's not taking up more than 90% of the width or height, the legend font is increased and the legend is created again and tested again to see whether it fills the desired span of the paper. This procedure is carried out for all of the legends created. The code that creates the legend looks something like this:
leg1_font = 15;
for i = 1:10
leg1 =legend(h(1:id(1,1)),legend_strings(id_lab(1:id(1,1))),'FontSize',leg1_font,'FontWeight','bold');
a= get(leg1,'Position')
if (a(1,4)) < .9 && a(1,3) < .9
leg1_font = leg1_font +1;
elseif (a(1,4)) > 1 || a(1,3)> 1
leg1_font = leg1_font -1;
else
break
end
end
set(leg1,'position',[0 0 a(3) a(4)]) %this sets the legend in the bottom left corner.
For some reason, the legend doesn't 'fill up' the majority of the paper space.
Can anyone give me a hand here?
much appreciated, Geoff

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!