MATLAB Answers

RuiQi
0

How to set legend marker size

Asked by RuiQi
on 16 Jul 2017
Latest activity Commented on by Abhijeet chausalkar on 3 May 2019
How do I change the marker size on the legend ? I can change the font size but not marker.
l = legend('Orientation', 'Horizontal', 'RNN (Ours)', 'SLIC', 'SEEDS', 'LSC', 'ERS', 'FH');
l.FontSize = 20;
%l.MarkerSize = 20; does not work
%l.markersize = 20; does not work
set(l,'Position', [0.4 0 0.2 0.2], 'Units', 'normalized');
%set(l,'MarkerSize', 20); does not work

  0 Comments

Sign in to comment.

3 Answers

Answer by Carl Witthoft on 11 Apr 2019

Best way: see Stackoverflow question 2871747
% thanks to , Luis Mendo and Lea
[~, objh] = legend({'one plot', 'another plot'}, 'location', 'NorthWest', 'Fontsize', 14);
%// set font size as desired
% note that even if you plot(x,y,'.') it's a "line" plot
objhl = findobj(objh, 'type', 'line'); %// objects of legend of type line
set(objhl, 'Markersize', 12); %// set marker size as desired
% or for Patch plots
objhl = findobj(objh, 'type', 'patch'); % objects of legend of type patch
set(objhl, 'Markersize', 12); % set marker size as desired

  2 Comments

If I recall correctly, R2018b / R2019a do not use line objects inside legends anymore.
I would need to recheck to be sure.
The command line with 'patch' worked for me in Matlab 2018a. I was really struggling to change the marker size using the code to plot a descent figure. Thanks Carl Witthoft.

Sign in to comment.


Answer by Akira Agata
on 16 Jul 2017

How about changing the marker size of your plot? Here is an example.
plot(magic(4),'o','MarkerSize',10);
l = legend('a','b','c','d');

  0 Comments

Sign in to comment.


Answer by Walter Roberson
on 16 Jul 2017

  2 Comments

I have the same problem and I'm using 2018a. Is there an answer to this. otherwise it almost makes the printed graphs useless because of the extremely tiny dots.
Did you experiment with Kelly's legendflex() ?

Sign in to comment.