How to enlarge legend marker size in r2014b?

38 views (last 30 days)
In previous versions one could grab the children of the legend object to change their size individually but now those don't exist anymore. How can I present larger markers in the legend that correspond to tiny scatter dots?
thanks!

Answers (2)

Kelly Kearney
Kelly Kearney on 20 Nov 2014
The marker handles are still there...
load seamount;
hs = scatter(x,y,5,z);
[hleg, hobj, hout, mout] = legend(hs, 'test');
hobj(2).Children.MarkerSize = 10;
  4 Comments
Kelly Kearney
Kelly Kearney on 21 Nov 2014
I've tracked the reverting-on-export issue to line 215 in print.m, which calls the private function alternatePrintPath.p... not quite sure what goes on under the hood there, but it seems to relink the legend to its labeled objects.
If you use my legendflex function instead, you can get the proper export, since the new "legend" isn't a real legend object and therefore decouples the label from the original data object:
hs = scatter(x,y,5,z);
[hleg, hobj, hout, mout] = legendflex(hs, {'test'});
set(get(hobj(2), 'Children'), 'markersize', 20);
(Though I'm a little behind in getting that function thoroughly R2014b-compatible. It works for most cases, but I still have some numeric handles left over that should be converted to graphics objects... I hope to get that cleaned up soon).
P.S. In response to Star, writing and maintaining legendflex.m is how I've learned my way around the inner workings of legends. I can't take credit for the bar offset property; I found this by the master of all things undocumented in another Answer.
Star Strider
Star Strider on 21 Nov 2014
Thanks for that link, Kelly. I’d not discovered it.
I’m going to keep R2014a installed in the event I actually need to do something!
R2014b is frustrating in its many limitations. (Among its other problems, the datetime functions cannot be used with surface plots. At least in some instances, setting options to override defaults doesn’t automatically switch the associated ‘Mode’ to 'manual'. That has to be done in a separate command in order to get the override to work.)

Sign in to comment.


Romesh
Romesh on 26 Nov 2017
Confirming on R2017a that the second output of legend has the necessary handles e.g.
[~,b] = legend('foo','bar','baz')
K>> b
b =
6×1 graphics array:
Text (a)
Text (b)
Text (c)
Group (a)
Group (b)
Group (c)
However, they are nested within the Group objects, and they are also a mixture of line and patch objects. An easy way to change the size then is to use findobj() to retrieve all of the handles with the MarkerSize property, and then to set them i.e.
set(findobj(b,'-property','MarkerSize'),'MarkerSize',10)
  2 Comments
Nike Dattani
Nike Dattani on 18 Nov 2018
This works for making the marker size bigger in the legend, but then the text is not interpreted by LaTeX, instead it's interpreted by TeX, and even changing it manually (by right clicking on the actual figure, for example), it does not get interpreted by LaTeX!
Nike Dattani
Nike Dattani on 18 Nov 2018
The font size also seems not to change :'(

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!