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.
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
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
In case anyone is like me and comes here looking for a way to change legend marker size for scatter plots: rather than objects of type 'line' as for line plots you need objects of type 'patch' (2017b).
objhl = findobj(objh, 'type', 'patch'); % objects of legend of type patch
set(objhl, 'Markersize', 12); % set marker size as desired
In my case I need to plot a multi-column legend in MATLAB R2019b (using the "NumCloumns" property), and I need to change the marker size in legend. Unfortunately these two requirements cannot be simultaneously fulfilled. MATLAB will ignore the "NumColumns" argument in you get two returns from the legend function.
I end up ploting some very large dots with the same color as the experiment data outside the axis limit and show legend of them. This works well though it is a dirty solution.
© 2022 - 2024 — McMap. All rights reserved.