# plotting several curves with the same function

Instead of using Show[Plot[f[x]/.{L->1},{x,0,1}],Plot[f[x]/.{L->2},{x,0,1}], Plot[f[x]/.{L->3},{x,0,1}]], I was wondering if there is a much simpler way by using some sort of replacing rule. Something like Plot[f[x]/.{L->1,L->2,L->3},{x,0,1}], and have the three curves on the same plot. Does Mathematica support something like this?

• Either {{L -> 1}, {L -> 2}, {L -> 3}} or take a look at Table etc. Related: 1731
– Kuba
Commented Sep 26, 2018 at 11:59

Let us fix the function f for this example, say, this way:

f[x_, L_] := (x/L)^2;


Then try this:

Plot[f[x, #] & /@ {1, 2, 3}, {x, 0, 1}]


or this:

Plot[Table[f[x, L], {L, {1, 2, 3}}], {x, 0, 1}]


or this:

Plot[Thread[f[x, #] &[{1, 2, 3}]], {x, 0, 1}]


They all return the following plot:

Have fun!

• Recommend that you also include use of Evaluate to distinguish between plots. Commented Sep 26, 2018 at 14:34

f[x_, L_] := (x/L)^2;


Either

Plot[Evaluate@Table[f[x, L], {L, {1, 2, 3}}], {x, 0, 1},
PlotLegends -> Placed["Expressions", {.25, .75}]]


or

Plot[Evaluate[f[x, #] & /@ {1, 2, 3}], {x, 0, 1},
PlotLegends -> Placed["Expressions", {.25, .75}]]


produce