필터 지우기
필터 지우기

How to plot legend above graph but not outside figure

조회 수: 13 (최근 30일)
Zayd Islam
Zayd Islam 2021년 3월 22일
편집: Cris LaPierre 2021년 3월 22일
I have a figure in a subplot and i want to put its legend above the graph but not outside the border. I have attatched an image of where i want the legend to be and preferably it should be oriented horizontally.
leg = legend('Healthy','Infected','Sick','Recovered');

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 3월 22일
Use the location name-value pair. See here.
leg = legend('Healthy','Infected','Sick','Recovered','Location','northeast');
  댓글 수: 2
Zayd Islam
Zayd Islam 2021년 3월 22일
Hi this isn't what i was looking for i want my legend to look like the image attatched thank you
Cris LaPierre
Cris LaPierre 2021년 3월 22일
편집: Cris LaPierre 2021년 3월 22일
So to clarify, the legend in Capture.PNG is NOT what you want? You can still use the linked page to explore the available properties. For example, to have it not outside the border, you could do this.
plot(1:10,rand(10,4))
legend('Healthy','Infected','Sick','Recovered',...
'Location','north',...
'Orientation','horizontal')
To have it look more like Capture2.PNG, you could do this.
figure
plot(1:10,rand(10,4))
box off
legend('Healthy','Infected','Sick','Recovered',...
'Location','northoutside',...
'Orientation','horizontal')
legend('boxoff');

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by