How to set legend marker size
205 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
Carl Witthoft
am 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
11 Kommentare
Gayan Lankeshwara
am 21 Jun. 2020
I am working in Matlab 2019a, but Carl's code does not work in my case for a line plot.
objhl = findobj(objh, 'type', 'line'); %// objects of legend of type line
set(objhl, 'Markersize', 12); %// set marker size as desired
I mean, even if I change the value of MarkerSize, nothing changes.
Any update ?
Thanks.
Walter Roberson
am 21 Jun. 2020
Are you using legend() with at least two output arguments? If you only have one output for legend then legend works differently.
Akira Agata
am 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');
2 Kommentare
Arnoud Jochemsen
am 15 Feb. 2022
Note that this only works up to a certain size. When using 15 instead of 10, the legend markers are clearly smaller than the plot markers.
plot(magic(4),'o','MarkerSize',15);
l = legend('a','b','c','d');
Walter Roberson
am 16 Jul. 2017
The exact version you are using makes a difference now.
2 Kommentare
Fernon Ejikhoudt
am 11 Jul. 2018
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.
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!