Is there a MATLAB official way to increase/decrease line length/icon size in legends?
32 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm making a a plot where the legend is quite long, here is minimal working example
plot(rand(4))
lgd = legend(["Directional Data","Median Direction",...
"Interquartile Range","Interquartile Slope Data"],...
"NumColumns",4,"Interpreter","latex");
lgd.Position = [0.4,0.0,0.2,0.05];
I would like to know if there is an official way to shorten the lengths of the lines for "Median Direction" and "Interquartile Range"? I have found several questions asking how to do this or similar things (you can look at the answers here: How can I modify the lengh of the lines in a LEGEND? - MATLAB Answers - MATLAB Central (mathworks.com)). Does MATLAB not have an official way of doing this? So far I've tried every answer I've come across and nothing seems to change the length of my legend lines.
0 commentaires
Réponse acceptée
Voss
le 19 Août 2023
Modifié(e) : Voss
le 19 Août 2023
I don't know if there's an official way, given that the outputs from legend() beyond the first one are not mentioned in the official documentation. And you're right, when you specify NumColumns and request the 2nd (or subsequent) output, NumColumns seems to be ignored, so the accepted answer to the linked-to question doesn't work in this case.
Here's a workaround (using the approach taken by the other answer to the linked-to question) that may be good enough, which decreases the length of all the lines in the legend.
plot(rand(4))
lgd = legend(["Directional Data","Median Direction",...
"Interquartile Range","Interquartile Slope Data"],...
"NumColumns",4,"Interpreter","latex");
lgd.Position = [0.4,0.0,0.2,0.05];
lgd.ItemTokenSize(1) = 12;
4 commentaires
Voss
le 19 Août 2023
lgd.ItemTokenSize(1) seems to be the width of the icons (lines) in the legend, and lgd.ItemTokenSize(2) seems to be the height.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!