Changing marker size in legends (gramm)
6 views (last 30 days)
Show older comments
I am using the gramm toolbox to do plots of all sorts in Matlab. One thing I'm having to always edit post-hoc in most plots (i.e. using the Property Inspector, instead of programatically adjusting gramm calls) is the marker size in legends, which by default are tiny. This amounts to increasing lineWidth:
Gramm does have a function dedicated to changing marker sizes, set_point_options, but that only refers to markers in the main plot, and does not affect those in the legend. Similarly, the set_text_options function has scaling parameters for the title & text of the legend, but not for the markers. Sadly, the toolbox's author is no longer available for support.
My usual way of changing legend marker sizes (for Matlab-native plot functions) is given below, but does not work with gramm plots:
x = 1:10;
plot(x, 1*x, 'o');
hold on;
plot(x, 2*x, 's');
[~, objh] = legend({'one','two'});
objhl = findobj(objh, 'type', 'line');
set(objhl, 'Markersize', 18);
% or, for Patch plots:
objhl = findobj(objh, 'type', 'patch');
set(objhl, 'Markersize', markerSize_legend);
3 Comments
Constantino Carlos Reyes-Aldasoro
on 8 Jun 2022
Why don't you define your properties directly from the plots:
x = 1:10;
plot(x, 1*x, 'o','markersize',9);
hold on;
plot(x, 2*x, 's','markersize',6);
You can also use handles to sort this without having to use any property inspector, but try this to see if it works. If not, let me know.
Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!