0
$\begingroup$

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?

$\endgroup$

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.

  • $\begingroup$ 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? $\endgroup$ – VF1 Mar 7 '13 at 5:01
  • $\begingroup$ yes, I want to label each line on the plane.(As l=10 for line corresponds to that) $\endgroup$ – TMH Mar 7 '13 at 5:02
  • $\begingroup$ change like this: dat = "L=" <> ToString@# & /@ {10, 20, 30, 40}; $\endgroup$ – yulinlinyu Mar 7 '13 at 5:10
  • $\begingroup$ @yulinlinyu Could you please send me the complete code which I want write? $\endgroup$ – TMH Mar 7 '13 at 5:14
  • $\begingroup$ Take a look at mathematica.stackexchange.com/a/14149/193 $\endgroup$ – Dr. belisarius Mar 7 '13 at 5:42
8
$\begingroup$

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

$\endgroup$
  • $\begingroup$ not like this. I want a label "l=10" near the line correspond to l=10 $\endgroup$ – TMH Mar 7 '13 at 5:06
  • $\begingroup$ 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. >> $\endgroup$ – TMH Mar 7 '13 at 5:18
  • $\begingroup$ @Vitaly Kaurov This is what I want. Unfortunately, I am getting an error. Could you explain me the reason? $\endgroup$ – TMH Mar 7 '13 at 5:23
  • $\begingroup$ @TMH You probably have some old definitions. Restart Mathematica. Or just compute Exit on a new line and re-evaluate. $\endgroup$ – Vitaliy Kaurov Mar 7 '13 at 5:23
  • $\begingroup$ Yes,It works now. Thanks a lot Vitaliy. $\endgroup$ – TMH Mar 7 '13 at 5:24

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