Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I have a question on plot labeling in Mathematica. I have

y = 4 x / L + 2

where

L = {10, 20, 30, 40}

I want to draw a graph of y vs. x. When I evaluate

Plot[y, {x, 0, 100}, 
   ImageSize -> Scaled[1.0],
   PlotLabel ->  Style["y vs X ", FontSize -> 18]]

I get four different lines in the same plot. I want to know how to label each line with its relevant L value; e.g., "l = 10" for the corresponding line.

Could anyone please tell me how to do this?

share|improve this question

marked as duplicate by Jens, m_goldberg, Mr.Wizard Mar 7 '13 at 6:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
As is, your plot plots all the lines on the same plane. Do you want an inset labeling each line on the plane, or four separate plots? –  VF1 Mar 7 '13 at 5:01
    
yes, I want to label each line on the plane.(As l=10 for line corresponds to that) –  TMH Mar 7 '13 at 5:02
    
change like this: dat = "L=" <> ToString@# & /@ {10, 20, 30, 40}; –  yulinlinyu Mar 7 '13 at 5:10
    
@yulinlinyu Could you please send me the complete code which I want write? –  TMH Mar 7 '13 at 5:14
    
Take a look at mathematica.stackexchange.com/a/14149/193 –  belisarius Mar 7 '13 at 5:42
add comment

1 Answer

up vote 3 down vote accepted

I think this is a duplicate but I couldn't find the original - so here it is along those lines:

y[x_, L_] := 4 x/L + 2

dat = {10, 20, 30, 40};

Plot[y[x, #] & /@ dat // Evaluate, {x, 0, 100}, 
 Epilog -> (Text["L = " <> ToString[#], {70, 0 + y[80, #]}] & /@ dat)]

enter image description here

share|improve this answer
    
not like this. I want a label "l=10" near the line correspond to l=10 –  TMH Mar 7 '13 at 5:06
    
I am getting an error like this. SetDelayed::write: Tag List in {2+(2 x)/5,2+x/5,2+(2 x)/15,2+x/10}[x_,L_] is Protected. >> –  TMH Mar 7 '13 at 5:18
    
@Vitaly Kaurov This is what I want. Unfortunately, I am getting an error. Could you explain me the reason? –  TMH Mar 7 '13 at 5:23
    
@TMH You probably have some old definitions. Restart Mathematica. Or just compute Exit on a new line and re-evaluate. –  Vitaliy Kaurov Mar 7 '13 at 5:23
    
Yes,It works now. Thanks a lot Vitaliy. –  TMH Mar 7 '13 at 5:24
show 2 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.