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

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Sean de Wolski
Sean de Wolski il 14 Giu 2011
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 Commenti
Matt Fig
Matt Fig il 14 Giu 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...

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by