# Why does contour plot not show point(s) where function has a discontinuity?

Consider the following code, which defines a function with a discontinuity, and then generates a contour plot when the function equals that discontinuity.

f[x_, y_] :=
Piecewise[{{Sqrt[x] + Log[y] + 2, x == 1 && y == 2}},
Sqrt[x] + Log[y]];
ContourPlot[{f[x, y] == f[1, 2]}, {x, .5, 1.5}, {y, 1.5,
2.5}, {ContourStyle -> {Black}}]


The output of this is a blank plot.

My question is:

• Why is this a blank plot? (1,2) should be on the contour since, by definition, we are plotting the contour through (1,2). is there any way to fix this?
• is it just that because it is just a point it cannot be displayed? If so, is there not a point-size option I can use to fix it?

Aside: Bonus question, as shown in the graph below, the points (9,2) and (1,2*Exp2) are also not included on the contour.

Why are these not included on the contour? I assume it is because of the discontinuity, but they have the correct value of the contour...

f[x_, y_] :=
Piecewise[{{Sqrt[x] + Log[y] + 2, x == 1 && y == 2}},
Sqrt[x] + Log[y]];
ContourPlot[{f[x, y] == f[1, 2]}, {x, .5, 15}, {y, 1.5,
25}, {ContourStyle -> {Black}, PlotPoints -> 500}]


gives an output of even though (9,1) and (1,2*Exp2) should be on the contour, as shown by

{f[1, 2], f[1, 2 E^2], f[9, 2]}
(* Out {3+Log[2],1+Log[2 \[ExponentialE]^2],3+Log[2]} *)

• Yes, only one point in the first cases. In the another cases, add Exclusions -> None. May 1, 2023 at 1:08

\$Version

(* "13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)" *)

Clear["Global*"]

f[x_, y_] :=
Piecewise[{{Sqrt[x] + Log[y] + 2, x == 1 && y == 2}}, Sqrt[x] + Log[y]];


The equation f[x, y] == f[1, 2] defines a single point in the region of interest

FindInstance[{f[x, y] == f[1, 2], 1/2 <= x <= 3/2, 3/2 <= y <= 5/2}, {x,
y}, Reals, 5]

(* {{x -> 1, y -> 2}} *)


To see the ContourPlot use

ContourPlot[f[x, y], {x, 1/2, 3/2}, {y, 3/2, 5/2},
ContourStyle -> Black,
Exclusions -> None,
PlotLegends -> Automatic]


f2[x_, y_] :=
Piecewise[{{Sqrt[x] + Log[y] + 2, x == 1 && y == 2}}, Sqrt[x] + Log[y]];

pts = {x, y} /.
FindInstance[{f2[x, y] == f2[1, 2], 1/2 <= x <= 15, 3/2 <= y <= 25},
{x, y}, 20];

Show[
ContourPlot[{f2[x, y] == f2[1, 2]},
{x, 1/2, 15}, {y, 3/2, 25},
ContourStyle -> Black,
PlotPoints -> 100,
MaxRecursion -> 5,
Exclusions -> None],
Graphics[{Red, AbsolutePointSize[4],
Point[pts]}]]
`

• Thank you very much. I did not know that Mathematica automatically excludes such points. Is it a good practice to always specify "Exclusions->None", or to always do so when working with functions with discontinuities? May 1, 2023 at 10:41
• Sometimes people want to see exclusions. Just be aware that the option is there and use it when it helps to do what you are trying to achieve. May 1, 2023 at 14:12