Hello everyone I want to ask how to reduce the length of the legend line.

31 vues (au cours des 30 derniers jours)
Hello everyone I want to ask how to reduce the length of the legend line.
xlabel("b) Tiempo, t(s)");
ylabel("Elevation free surface, η(m)");
legend(["Coarse","Medium","Fine"],'Location','northwest',"NumColumns",2);
legend('boxoff');

Réponse acceptée

Abderrahim. B
Abderrahim. B le 2 Août 2022
Hi!
Perhaps this:
figure
hold on
plot(1:10, randi(5,10,1))
plot(1:10, randi(10,10,1))
% Modify x1 and x2 based on your requirements
x1 = 5 ;
x2 = 5 ;
leg = legend('Plot1','Plot2');
leg.ItemTokenSize = [x1, x2];
Hope this helps
  2 commentaires
Juan David Parra Quintero
Juan David Parra Quintero le 2 Août 2022
Hey seriously thank you very much, your code helped me. I ask you how I could increase the width of each line of the legend.
Abderrahim. B
Abderrahim. B le 2 Août 2022
Modifié(e) : Abderrahim. B le 2 Août 2022
Maybe this workaround:
figure
hold on
plot(1:10, randi(5,10,1))
plot(1:10, randi(10,10,1))
% Modify x1 and x2 based on your requirements
x = [10, 10] ; % length
[legh, legObj, ~, ~] = legend('Plot1','Plot2' );
hlegObj = findobj(legObj,'type','line');
lineW = 2 ; % Line Width
set(hlegObj,'LineWidth',lineW);
legh.ItemTokenSize = x ;
legh.Box ='off' ;

Connectez-vous pour commenter.

Plus de réponses (1)

Juan David Parra Quintero
Juan David Parra Quintero le 2 Août 2022
Thanks my friend !!
  2 commentaires
Abderrahim. B
Abderrahim. B le 2 Août 2022
My pleasure!
If you found my answer helpful, make sure to accept it.
Juan David Parra Quintero
Juan David Parra Quintero le 4 Août 2022
Do you know how to increase the marks of values on the x and y axis in matlab? The X axis should be by year to year

Connectez-vous pour commenter.

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by