Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the symbols size in a figure legend

Is there an option to change the symbol size in the legend that Matlab creates? I only want to increase the symbol size in the legend. I have used 4 scatters of 3 points each.

like image 751
Alon8200 Avatar asked Dec 05 '22 22:12

Alon8200


1 Answers

Matlab R2014b or newer (HG2)

The organization of the elements in the legend is now different. The following works:

plot(1:10, 'o-'); 
hold on
plot(5:12, 'r*--'); %// example plots
[~, objh] = legend({'one plot', 'another plot'}, 'location', 'NorthWest', 'Fontsize', 14);
%// set font size as desired
objhl = findobj(objh, 'type', 'line'); %// objects of legend of type line
set(objhl, 'Markersize', 12); %// set marker size as desired

enter image description here

Matlab R2014a or older

To increase font size: get handles to all legend's children of type 'text', and set their 'Fontsize' property to the desired value.

To increase marker size: get handles to all legend's children of type 'line', and set their 'Markersize' property to the desired value.

plot(1:10, 'o-'); 
hold on
plot(5:12, 'r*--'); %// example plots
h = legend('one plot', 'another plot', 'location', 'NorthWest'); %// example legend
ch = findobj(get(h,'children'), 'type', 'text'); %// children of legend of type text
set(ch, 'Fontsize', 14); %// set value as desired
ch = findobj(get(h,'children'), 'type', 'line'); %// children of legend of type line
set(ch, 'Markersize', 12); %// set value as desired

enter image description here

like image 62
Luis Mendo Avatar answered Jan 08 '23 07:01

Luis Mendo