1
$\begingroup$

The following produces an empty plot:

eqn = x^2 + y^2 == 1;
ContourPlot[eqn, {x, -1, 1}, {y, -1, 1}]

Whereas the following plots a circle, as expected:

ContourPlot[x^2 + y^2 == 1, {x, -1, 1}, {y, -1, 1}]

What do I need to do to get the former to work with eqn? My actual eqn is a complicated list of equations.

I am sure this is elementary...

$\endgroup$
5
  • 1
    $\begingroup$ ContourPlot[Evaluate@eqn, {x, -1, 1}, {y, -1, 1}] $\endgroup$
    – Michael E2
    Aug 18, 2016 at 18:54
  • $\begingroup$ @MichaelE2: Ah, thanks! Is there a short explanation of why Evaluate is needed here? Is it because ContourPlot has attribute HoldAll? $\endgroup$ Aug 18, 2016 at 18:56
  • $\begingroup$ I found an explanation here. Thanks! $\endgroup$ Aug 18, 2016 at 19:07
  • 2
    $\begingroup$ Yep, you found it. All commands that plot functions or equations are HoldAll. In this specific case, ContourPlot sees the unevaluated symbol eqn and decides it's a function, not an equation, because the Head is Symbol and not Equal. (I think it could be changed so that Evaluate is not needed in this case, but until it's changed, Evaluate is what you have to use.) $\endgroup$
    – Michael E2
    Aug 18, 2016 at 19:18
  • $\begingroup$ @user21: Yes, I linked to that in a comment above. It is a duplicate, and there is a clear explanation there by two users. $\endgroup$ Aug 18, 2016 at 21:31

0

Browse other questions tagged or ask your own question.