MATLAB Answers

having legend title and enlarging legend marker size at the same time

4 views (last 30 days)
CS
CS on 20 Nov 2020
Edited: VBBV on 20 Nov 2020
Initially I had a legend as like this
As you can see, the size of the legend marker is much smaller than the size of the scatter marker. However, the legend has a title. I used below code for this:
lgd=legend('25','50','75','100','Location','northwest','FontSize',30);
lgd.Title.String = 'Recoating Velocity (%)';
lgd.Title.FontSize = 30;
Then, in order to increase the marker size in the legend, I used the icons as below:
[lgd,icons,plots,legend_text] = legend('25','50','75','100', 'Location', 'Northwest')
for k = 5:8
icons(k).Children.MarkerSize = 20;
end
lgd.Title.String = 'Recoating Velocity (%)';
lgd.Title.FontSize = 30;
And the result looks like this:
Although the marker size increased, but the legend title is not applied. Why is that? How to fix it?

  0 Comments

Sign in to comment.

Answers (1)

VBBV
VBBV on 20 Nov 2020
Edited: VBBV on 20 Nov 2020
%f true
%lgd.MarkerSize = 20
set(lgd,'MarkerSize',20);
lgd.Title.String = 'Recoating Velocity (%)';
lgd.Title.FontSize = 30;
Try this. You can try using set function and its handle

  5 Comments

Show 2 older comments
VBBV
VBBV on 20 Nov 2020
Ok. Markersize is not property class of legend.
You can try my 2nd option. Use NumColumns to 2 as arguemnt in legend to view the legend titled
CS
CS on 20 Nov 2020
I tried that way as well, but the marker size stays as small as it was previously. This solution has nothing to do with the marker size; it only changes the legends to two coloumns.
VBBV
VBBV on 20 Nov 2020
%if true
lgd=legend({'25','50','75','100'},'Position', [0.2 0.6 0.2 0.4],'Location','northwest','FontSize',30);
lgd.Title.String = 'Recoating Velocity (%)';
lgd.Title.FontSize = 30;
You can try with position property to set the size of legend box. Adjust the dimensions to fit both title and markers

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!