# A particular contour does not show up, even though it is in my list [duplicate]

Consider:

f = Sqrt[9 - x^2 - y^2];
ContourPlot[f, {x, -4, 4}, {y, -4, 4},
Contours -> {0, 1, 2, 3},
ContourLabels -> All,


Which produces this image:

Now, I understand that the contour f=3 is just the point (0,0) and maybe that's why it's not drawn. But I don't understand why the contour f=0, which should be a circle of radius 3, is missing?

Any thoughts?

• For x=y=3, f is complex Jul 8, 2015 at 19:20
• @EnriquePérezHerrero 9 - x^2 - y^2 /. {x -> 3/Sqrt@2, y -> 3/Sqrt@2} Jul 8, 2015 at 19:23
• Sqrt[9 - 3^2 - 3^2] = 3i Jul 8, 2015 at 19:25
• @EnriquePérezHerrero: When finding the contour $f=0$, we're working with $\sqrt{9-x^2-y^2}=0$, which is equivalent to $x^2+y^2=9$, which is a circle of radius 3. We are not substituting 3 for $x$ and $y$. But see Michael Seifert's answer. But thanks for the reply. Jul 8, 2015 at 20:05
• Possible duplicates: (23363), (32734) Jul 8, 2015 at 22:59

It appears to be a problem with the square root:

f = 9 - x^2 - y^2;
ContourPlot[f, {x, -4, 4}, {y, -4, 4}, Contours -> {0, 1, 4, 9},
ContourLabels -> (Text[Sqrt[#3], {#1, #2}] &), ContourShading -> None]


My guess is that the algorithm used by ContourPlot implicitly relies on the function having a smooth gradient in some neighborhood of each contour, which the function $f = \sqrt{9 - x^2 - y^2}$ does not have in the neighborhood of the level set $f = 0$.

• Probably a good point. Thanks for the help. Jul 8, 2015 at 19:53
f = Sqrt[9 - x^2 - y^2];

Reduce[f == 0, {x, y}, Reals]


-3 <= x <= 3 && (y == -Sqrt[9 - x^2] || y == Sqrt[9 - x^2])

Mathematica has a hard time finding a real solution for f == 0. Using a large number of PlotPoints and forcing the result to be real using Re produces a highly segmented plot (multiple labels for 0)

ContourPlot[Re[f], {x, -4, 4}, {y, -4, 4}, Contours -> {0, 1, 2, 3},
ContourLabels -> All,
PlotPoints -> 201]


For a workaround use RegionPlot:

Row[{
RegionPlot[
ImplicitRegion[
Reduce[
Sqrt[9 - x^2 - y^2] == #, {x, y}, Reals],
{x, y}] & /@
Range[0, 3],
PlotRange -> {{-4, 4}, {-4, 4}},
ImageSize -> 360],
LineLegend[
{Red, Darker[Green], Orange, Blue},
Range[3, 0, -1]]}]