This question already has an answer here:
I have a list of linear inequalities which describe a (polygonal) region. I can use RegionPlot to visualize this region; but I'd also like to overlay this plot with the lines corresponding to each inequality. ContourPlot works for drawing the lines, but only if I put my list of equations as it's argument -- if I put a variable holding the list of equations I get nothing out.
constraints = {
x <= 2,
x + 2 y >= 2,
x + 2 y <= 6,
x - 2 y >= -2,
3 x + 6 y <= 18
}
region = And @@ constraints
equations = constraints /. { LessEqual -> Equal, GreaterEqual -> Equal}
p1 = RegionPlot[region, {x, -1, 3}, {y, -1, 3}]
This shows the region nicely shaded in blue. The variable "equations" is set to a list of equations of the lines I'd like to highlight; it's value is
{x == 2, x + 2 y == 2, x + 2y == 6, x - 2y == -2, 3x + 6y == 18}
Now I try to plot these lines:
p2 = ContourPlot[equations, {x, -1, 3}, {y, -1, 3}]
This results in an empty plot!
However, if I copy-and-paste the value of "equations" right into the code, it renders a nice plot:
p2 =
ContourPlot[{x == 2, x + 2y == 2, x + 2y == 6, x - 2y == -2, 3x + 6y == 18},
{x, -1, 3}, {y, -1, 3}]
To wrap up, I overlay the two plots:
Show[p1, p2]
Why does ContourPlot see a difference between the two invocations? My understanding is that they should be equivalent.

constis. But either way, tryContourPlot[Evaluate@equations, {x, -1, 3}, {y, -1, 3}]do ??ContourPlotAttributes[ContourPlot]={HoldAll,Protected,ReadProtected}– Nasser Mar 11 at 3:03const, oops, that's a cut-and-paste-error. It should beconstraints. I've fixed it now. – Jim Meier Mar 11 at 5:50