I'm trying to do a simple variable substitution within a ContourPlot, but it's not working. Here's an example:

ContourPlot[x y == 1/2, {x, 0, 1}, {y, 0, 1}] 
ContourPlot[x y == 1/2 /. y -> z, {x, 0, 1}, {z, 0, 1}]

The second line, although mathematically identical, produces no contour. Why? How can I do the substitution correctly?

Edit: It looks like my initial question is solved by simply wrapping the argument in Evaluate. However, why doesn't Plot obey the same rules? The following works without Evaluate:

Plot[x, {x, 0, 1}]
Plot[x /. x -> z, {z, 0, 1}]
  • $\begingroup$ Please don't quickly change your question as soon as you get an answer. Duplicate of mathematica.stackexchange.com/q/1375/5, mathematica.stackexchange.com/q/1731/5, mathematica.stackexchange.com/q/3270/5 and several others $\endgroup$
    – rm -rf
    Feb 2 '13 at 0:17
  • $\begingroup$ Should I have just deleted the question and submitted a revised one? It's not clear to me why ContourPlot would have HoldAll, and Plot would not...and if there's a general rule for which routines have HoldAll or not. $\endgroup$
    – Guillochon
    Feb 2 '13 at 0:25
  • $\begingroup$ Alright, I guess both have HoldAll, from the links you provided. I'm still confused as to why the Plot command works without the Evaluate... $\endgroup$
    – Guillochon
    Feb 2 '13 at 0:30
  • 2
    $\begingroup$ ContourPlot has several "modes", one of which is to display contours corresponding to one or a list of equalities. Your expression is a ReplaceAll, so ContourPlot uses its default mode. (The ReplaceAll contains an equality, but ContourPlot doesn't see that.) In default mode, your expression evaluates to False or True, which are not real numbers, so nothing is displayed. Plot also has several modes, but your given expression works fine for the default one. $\endgroup$
    – Xerxes
    Feb 2 '13 at 0:46

Try :

ContourPlot[Evaluate[x y == 1/2 /. y -> z], {x, 0, 1}, {z, 0, 1}]
  • $\begingroup$ b.gatessucks: I ending up figuring this out too, so I modified my question to ask something related which still confuses me. $\endgroup$
    – Guillochon
    Feb 2 '13 at 0:12

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