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

This question already has an answer here:

Consider:

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


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?

## marked as duplicate by Michael E2 plotting StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jul 9 '15 at 5:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• For x=y=3, f is complex – Enrique Pérez Herrero Jul 8 '15 at 19:20
• @EnriquePérezHerrero 9 - x^2 - y^2 /. {x -> 3/Sqrt@2, y -> 3/Sqrt@2} – Dr. belisarius Jul 8 '15 at 19:23
• Sqrt[9 - 3^2 - 3^2] = 3i – Enrique Pérez Herrero Jul 8 '15 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. – David Jul 8 '15 at 20:05
• Possible duplicates: (23363), (32734) – Michael E2 Jul 8 '15 at 22:59

## 2 Answers

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. – David Jul 8 '15 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,
ContourShading -> None,
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]]}] 