# ReplaceAll and PlotStyle and PlotLegends in multiple curves [duplicate]

Why do PlotStyle and PlotLegends take only a single style for all the curves if ReplaceAll rule is outside the bracket?

Plot[{α x, x^2 α} /. {α -> 2.5}, {x, -2, 6},
PlotRange -> {{-2, 6}, {-1, 6}},
PlotStyle -> {{Dotted, Blue, Thick}, {Dashed, Red}}, Frame -> True,
PlotLegends -> {"V[ϕ]", "ϵ[ϕ]"}
]


Versus

Plot[{α x /. {α -> 2.5}, x^2 α /. {α -> 2.5}}, {x, -2, 6},
PlotRange -> {{-2, 6}, {-1, 6}},
PlotStyle -> {{Dotted, Blue, Thick}, {Dashed, Red}}, Frame -> True,
PlotLegends -> {"V[ϕ]", "ϵ[ϕ]"}
]


The behavior is same even for ParametricPlot and for more than two curves.

## 1 Answer

Plot has Hold attributes, like all the other plotting functions. This means that sometimes it does not not recognize the fact that its argument is a list if the head of that argument is not explicitly List. See: Plot draws list of curves in same color when not using Evaluate.

In your first case, the head of the expression in the first argument of Plot is ReplaceAll before evaluation, so Plot sets up a single style for it:

HoldForm[{α x, x^2 α} /. {α -> 2.5}] // FullForm

(* Out:
HoldForm[ReplaceAll[
List[Times[α, x], Times[Power[x, 2], α]],
List[Rule[α, 2.5]]
]
]
*)


In your second case, the head of the expression is List, so Plot recognizes that it needs to use more than one style:

HoldForm[{α x /. {α -> 2.5}, x^2 α /. {α -> 2.5}}] // FullForm

(* Out:
HoldForm[
List[
ReplaceAll[Times[α, x], List[Rule[α, 2.5]]],
ReplaceAll[Times[Power[x, 2], α], List[Rule[α, 2.5]]]
]
]
*)


As usual, the solution is to explicitly Evaluate the first argument:

Plot[Evaluate[{α x, x^2 α} /. {α -> 2.5}], {x, -2, 6},
PlotRange -> {{-2, 6}, {-1, 6}},
PlotStyle -> {{Dotted, Blue, Thick}, {Dashed, Red}},
Frame -> True, PlotLegends -> {"V[ϕ]", "ϵ[ϕ]"}
] • +1.This answer in combination with Matariki's answer to the linked question makes the stucture of HoldAll, ReplaceAll, within the context of plotting functions and how Evaluate can change the head to List for desired result. – Sluth Jul 30 '16 at 3:08
• Problem: even though the head of {{[Alpha] x, x^2 [Alpha]} /. {[Alpha] -> 2.5}} is list, still plot showing single style! – Sluth Jul 30 '16 at 3:15