change legend line segment width in version 2018

I am using version 2018 because it allows multicolumn legends.
plot(rand(6))
legend({'Line 1','Line 2','Line 3','Line 4','Line 5','Line 6'},'FontSize',12,'NumColumns',2)
However, I would also like to control the width of the line segment that appears in the legend. Is there a way to make it wider or shorter? The LineWidth property will change the thickness of the line. I do not want that.

답변 (1개)

Rik
Rik 2018년 3월 25일

0 개 추천

The style of the legend item is inherited from the object itself, so you can make the line thicker, but only if you make the line itself thicker as well.
Also: if you're planning on sharing this code with anyone, you should be aware that the NumColumns property was introduced in R2018a, so anyone not on that release will not be able to run your code.
If that is not acceptable to you, you will have to re-implement a legend function yourself. I would advise you to take a look on the File Exchange if anybody has done something you can use.

댓글 수: 2

I have used legendlfex function from File Exchange. That does the job,but is buggy for multicolumn legends.
Rik
Rik 2018년 3월 26일
If you can't solve your issue: having a limit on what version people can use to run your code is not necessarily a problem, but it is something you should be aware of and ideally report in your function header/help text.

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2018년 3월 25일

댓글:

Rik
2018년 3월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by