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 Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by