Is there a MATLAB official way to increase/decrease line length/icon size in legends?
30 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2023-8-19
编辑:Voss
2023-8-19
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 个评论
Voss
2023-8-19
lgd.ItemTokenSize(1) seems to be the width of the icons (lines) in the legend, and lgd.ItemTokenSize(2) seems to be the height.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!