How to enlarge legend marker size in r2014b?
13 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(2 个)
Kelly Kearney
2014-11-20
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 个评论
Kelly Kearney
2014-11-21
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
2014-11-21
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.)
Romesh
2017-11-26
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 个评论
Nike Dattani
2018-11-18
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!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!