Change legend line style

不问归期 提交于 2019-12-04 02:15:22

问题


I am playing with the visual effect of plots, and a question came up while changing the style of a legend.

To be able to save the figure with legends big enough that can be seen usually one needs to change the FontSize property to e.g. 24. When you do that, the size of the font changes, however, the small line next to it has the same size than when it was small. The proportion between line/text seem quite appropriate to me with a FontSize of around 10, while I believe that with big font sizes bigger "eat" visually the line, which is the important part.

Example with fontsize 30 and 10 (please ignore how much I suck in mspaint and the low resolution of the zoomed legend). The proportion between line/text is nicer in the small one.

I was wondering if there is a way to modify that line. I have been checking the properties but I haven't found any relevant one.

NOTE: The LineWidth property does not change the width of the colour lines, but the width of the bounding box.


回答1:


You could play with the outputs arguments of legend, especially the icons variable (check here).

According to the docs, they correspond to

Objects used to create the legend icons and descriptions, returned as text, patch, and line object.

Therefore you might use something like this to modify the LineWidth property of any of your plot, or both of course:

clear
clc
close all
x = 1:10;

plot(x,rand(1,10));
hold on;

plot(x,x,'k');

[h,icons,plots,str] = legend('First plot','Second plot','Location','NorthWest');

set(h,'FontSize',30);

set(icons(:),'LineWidth',2); %// Or whatever

Which outputs:

Note that I used R2014a so it might be a bit different for R2014b.



来源:https://stackoverflow.com/questions/28587252/change-legend-line-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!