MATLAB Answers

Scale a Legend with the underlying Axis

12 views (last 30 days)
Simon Kölbl
Simon Kölbl on 15 Sep 2017
Commented: Felix Schönig on 7 Jan 2021
Hi,
I'm trying to make a figure, of fixed size, with multiple subplots. The number of subplots, and thus the size of each can vary. Each subplot may have a dedicated legend. The Problem is, that the Legend always has the same size regardless of the size of the subplots. So if the subplots become small the legend is way to big.
I noticed that the legend scales with its FontSize, so I figured, if I set the FontUnits of the Legend to normalized it would to the trick. Though I am able to set the FontUnits property of the legend, its FontSize is still displayed in Pts and it won't scale when changing the subplot size.
So, is there a smart way to have the legend scale with the underlying Axis?
Best regards

Answers (1)

Ramnarayan Krishnamurthy
Ramnarayan Krishnamurthy on 21 Sep 2017
The observation that the size of the legend scales with the Font Size is true. Is there a reason you would prefer not to change the Font Size in that case?
As in, assuming you have the handle to the legend of a subplot in 'a':
a.FontSize = 4;
Another approach would be to set the size of the legend as follows:
set(a ,'Position', [0.8 0.2 0.05 0.5])
This will require figuring out the appropriate x and y values for the position vector.
  2 Comments
Felix Schönig
Felix Schönig on 7 Jan 2021
I am having the same problem. Did you find a solution?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by