## Why is the marker size in the legend of a SCATTER plot not equal to the marker size in the plot?

### MathWorks Support Team (view profile)

on 2 Dec 2009
Latest activity Commented on by Girmi Schouten

### Girmi Schouten (view profile)

on 10 Apr 2017
Accepted Answer by MathWorks Support Team

### MathWorks Support Team (view profile)

If I execute the following code:

figure; hold on
s1 = scatter(1, 1, 150, 'k', 'o')
s2 = scatter(1, 2, 150, 'k', '+')
s3 = scatter(2, 1, 150, 'k', 'x')
h = legend('Circle', 'Plus', 'X', 'Location', 'NorthEast');
set(h, 'FontSize', 14)
axis([0 3 0 3])
the marker size in the legend is different from that in the scatter plot. How can I set these marker sizes to be equal when using the SCATTER function?

R2009b

### MathWorks Support Team (view profile)

on 18 Oct 2013

The ability to automatically equalize the marker size of the legend and plot markers when using the SCATTER function is not available in MATLAB 7.9 (R2009b).
You may use either of the following workarounds to create a scatter plot in which the legend markers have the same size as the plot markers:
1. Manually set the marker size of the patch objects in the legend. Note that the marker area input to the SCATTER function is specified in square points, whereas the 'MarkerSize' property of a patch object is given in points:

M = findobj(h,'type','patch') % Find objects of type 'patch'
set(M,'MarkerSize', sqrt(150)) %Calculate marker size based on size of scatter points
Note that this workaround only applies to releases R2014a and prior. The legend graphics object hierarchy changed in R2014b.
2. Use the PLOT function instead of the SCATTER function:

figure; hold on
plot(1,1,'ko', 'MarkerSize', 12)
plot(1,2,'k+', 'MarkerSize', 12)
plot(2,1,'kx', 'MarkerSize', 12)
h = legend('Circle', 'Plus', 'X', 'Location', 'NorthEast');
set(h, 'FontSize', 14)
axis([0 3 0 3])

Graham

### Graham (view profile)

on 10 Mar 2014
Fantastic! I used option #1 with scatter.
vkamp

### vkamp (view profile)

on 17 Aug 2015
I am using the R2014b version and I had this problem when using both scatter and plot function. I couldn't equalize the marker size in the plot with that of the legend. I finally solved the problem when used only the plot function, avoiding to use the scatter function, even for single point plots. That solved the problem for me.

### Orion (view profile)

on 23 Jun 2015

M = findobj(h,'type','patch') % Find objects of type 'patch'
set(M,'MarkerSize', sqrt(150)) %Calculate marker size based on size of scatter points
How can we do this in MATLAB R2015a?

Luc

### Luc (view profile)

on 14 Aug 2015
I am having the same problem here using Matlab 2015a. Does anyone have a fix for that. Right now, the markers in my legend are smaller than on the figure and are hardly distinguishable.
Benjamin Campforts

### Benjamin Campforts (view profile)

on 29 Feb 2016
I used a combination of previous answers for that:
[l, hobj, hout, mout] = legend(...);
M = findobj(hobj,'type','patch');
set(M,'MarkerSize',50);
This works for me in Matlab 2015a. Good luck!
Girmi Schouten

### Girmi Schouten (view profile)

on 10 Apr 2017
Works in MATLAB 2016b. Nice find, thanks for sharing!