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

1 次查看(过去 30 天)
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...

请先登录,再进行评论。

更多回答(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