Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase marker size of the legend in scatter plot in MATLAB 2014b? [duplicate]

I found marker size in the scatter plot and the legend is different in MATLAB 2014b. I searched & found some solution from earlier version of MATLAB, which are not applicable in the latest version. In my current version, the marker size in legend is so small that it is hardly distinguishable. Any help?

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 scatter and legend is different. How can I increase the marker size of legend entries & makes it similar to that of the scatter plot.

like image 524
user962808 Avatar asked Sep 18 '15 14:09

user962808


People also ask

Which attribute is used to change the size of marker?

Output: Example 2: To adjust the size of marker in a plot use markersize parameter to plot method to adjust the marker size.

How do you edit a legend in MATLAB?

If you double-click on a text label in a legend, MATLAB opens a text editing box around all the text labels in the legend. You can edit any of the text labels in the legend. To access the properties of these text objects, right-click on a text label and select Properties from the context-sensitive pop-up menu.


1 Answers

If I understand right, you want to access the icons output of the call to legend and modify the MarkerSize property of the patch objects that are children of those icons.

Call to legend:

[h,icons,plots,legend_text] = legend('Circle', 'Plus', 'X', 'Location', 'NorthEast'); 

icons is a 6x1 graphics array like so:

icons = 

  6x1 graphics array:

  Text     (Circle)
  Text     (Plus)
  Text     (X)
  Group    (Circle)
  Group    (Plus)
  Group    (X)

What you need are the elements associated with a Group.

If you look at their properties (here icons(4)), you get:

icons(4)

 Group (Circle) with properties:

    Children: [1x1 Patch]
     Visible: 'on'
     HitTest: 'off'

  Show all properties

So there is a patch object associated with it as its child. You want to modify it using for instance

icons(Some index).Children.MarkerSize

In your case, you need to modify objects 4 to 6:

for k = 4:6
icons(k).Children.MarkerSize = 20;
end

which outputs:

enter image description here

you can automate this of course. I used R2015a so I expect the behavior to be the same for R2014b.

Hope this is what you meant!

like image 140
Benoit_11 Avatar answered Oct 09 '22 00:10

Benoit_11