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

조회 수: 55 (최근 30일)
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');

채택된 답변

Abderrahim. B
Abderrahim. B 2022년 8월 2일
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
Juan David Parra Quintero
Juan David Parra Quintero 2022년 8월 2일
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 2022년 8월 2일
편집: Abderrahim. B 2022년 8월 2일
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' ;

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

추가 답변 (1개)

Juan David Parra Quintero
Juan David Parra Quintero 2022년 8월 2일
Thanks my friend !!
  댓글 수: 2
Abderrahim. B
Abderrahim. B 2022년 8월 2일
My pleasure!
If you found my answer helpful, make sure to accept it.
Juan David Parra Quintero
Juan David Parra Quintero 2022년 8월 4일
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

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

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by