Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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}]
share|improve this question

marked as duplicate by Szabolcs, Sjoerd C. de Vries, m_goldberg, rcollyer, Oleksandr R. Feb 14 '13 at 4:26

This question was marked as an exact duplicate of an existing question.

Please don't quickly change your question as soon as you get an answer. Duplicate of,, and several others – R. M. Feb 2 '13 at 0:17
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. – Guillochon Feb 2 '13 at 0:25
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... – Guillochon Feb 2 '13 at 0:30
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. – Xerxes Feb 2 '13 at 0:46

Try :

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

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