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

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?

 Respuesta aceptada

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 comentarios

George
George el 14 de Jun. de 2011
can you write me the code for 10 lines in a row ? with text1,tex2,...,text10 as example, please ?
Matt Fig
Matt Fig el 14 de Jun. de 2011
Or, you could just read the documentation, like Sean de suggested. Have a look at it, there are even examples there! Type this at the command line, then hit return. A window will pop up, read it.
doc legend
George
George el 14 de Jun. de 2011
i have a subplot of three plots, and i want it to be outside the plots, on the right side of the border.
Matt Fig
Matt Fig el 14 de Jun. de 2011
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 el 14 de Jun. de 2011
did it

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 14 de Jun. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by