How to increase the length of the legend line?
Afficher commentaires plus anciens
Hello, I would like to increase the length (not linewidth) of the line inside the legend. Does anyone has an idea? Thanks you.
t = [0:0.1:2*pi]
a = sin(t);
b = cos(t);
plot(t,a,t,b,'linewidth',3)
l = legend({'Sinus','Cosinus'},...
'location','southwest','FontName','TimesNewRoman','FontSize',20);

1 commentaire
KALYAN ACHARJYA
le 21 Avr 2018

Réponses (3)
KALYAN ACHARJYA
le 21 Avr 2018
Modifié(e) : Walter Roberson
le 8 Sep 2020
2 votes
I don't think it is customizable directly, go to the following links to user-defined function-
4 commentaires
Arpan Sircar
le 29 Mar 2019
The simplest way to do it is to use: -
leg = legend('Plot1','Plot2',...);
leg.ItemTokenSize = [x1,x2];
By default x1=30 and x2=18 so put larger or smaller numbers as x1,x2 to increase or decrease the legend line size.
Minh Chien Trinh
le 24 Juil 2019
Thank you Arpan Sircar.
It works well.
Luca Menegozzo
le 28 Nov 2020
Modifié(e) : Luca Menegozzo
le 28 Nov 2020
The best solution to the problem without extra functions. Thank you!
Tin Truong Chanh
le 13 Jan 2021
thank you Arpan Sircar
Starting in R2024b, you can leverage the IconColumnWidth property on legend to increase the length of the line:
t = [0:0.1:2*pi]
a = sin(t);
b = cos(t);
plot(t,a,t,b,'linewidth',3)
l = legend({'Sinus','Cosinus'},...
'location','southwest','FontName','TimesNewRoman','FontSize',20);
l.IconColumnWidth = 60;
Catégories
En savoir plus sur Legend dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
