How do I make something that labels the lines in my plot?

조회 수: 1 (최근 30일)
George
George 2011년 6월 14일
I have a plot with many lines in it that pointing some spots.
I want to create a matrix outside the plot area, a list, that will say the name of each drawn line. How can I do that?

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 6월 14일
doc legend
?
Edited
%Demo
H = zeros(4,1); %preallocate handle vector
M = magic(4); %magic square to have each row plotted
x = 1:4; %index 1:4
names = {'Line 1','Line 2','Line 3','Line 4'}; %sample line names (creative I know!)
style = {'r-','b:','k--','c:*'}; %sample line styles
figure; hold on
for ii = 1:4
subplot(121+(rand>.5)); %random subplot loc
hold on
H(ii) = plot(x,M(ii,:),style{ii}); %plot and record handle
end
legend(H,names{:},'location','southwestoutside') %outside bottom left legend
  댓글 수: 5
Matt Fig
Matt Fig 2011년 6월 14일
Once you make a legend, you can click on it and move it to wherever you want. Did you mean that you have three plots on the same axes or that you have used the SUBPLOT function?
You see, this is why you should tell us the whole problem up front, instead of making us answer it piece-meal. Please go back and edit your original post by clicking on the Edit button. Then describe the entire problem including all relevant details. It would really help to include sample code that we can copy and paste to show us what you are looking at. It needn't be your original data, you can use fake data like x = rand(1,5), etc...
George
George 2011년 6월 14일
did it

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

추가 답변 (0개)

카테고리

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