# One Mesh Line does not show up in ContourPlot

Consider:

f = 0.5 (x^2 + y^3);
ContourPlot[f, {x, -1, 1}, {y, -1, 1},
MeshFunctions -> {Function[{x, y, z}, x],
Function[{x, y, z}, 3 y^2/2]}, Mesh -> {{0}, {0}},
MeshStyle -> {Directive[Thick, Yellow],
Directive[Red, Thick, Dashed]}]


Which produces this image.

Why doesn't the Red, Thick, Dashed mesh show up?

Example showing why it will not just be lines:

f[x_, y_] = x^2 - 4 x y/(y^2 + 1);
ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2},
MeshFunctions -> {Function[{x, y, z}, Evaluate@D[f[x, y], x]],
Function[{x, y, z}, Evaluate@D[f[x, y], y]]},
Mesh -> {{0}, {0}},
MeshStyle -> {Directive[Thick, Dashed, Red],
Directive[Thick, Yellow]}]


Which produces:

• what's f? You haven't defined it. Jul 8, 2015 at 18:25
• @rcollyer Sorry, update now includes f. Jul 8, 2015 at 18:43
• Jul 9, 2015 at 0:44

You are looking at the zero of the function $y^2/2$, which is a zero of order 2. This makes it hard for the numeric function to find this. Play a little with the value, and you get the desired result.

f = 0.5 (x^2 + y^3);
ContourPlot[f, {x, -1, 1}, {y, -1, 1},
MeshFunctions -> {Function[{x, y, z}, x],
Function[{x, y, z}, 3 y^2/2]},
Mesh -> {{0}, {10^-7}},
MeshStyle -> {Directive[Thick, Yellow], Directive[Red, Thick, Dashed]}]


• BTW, wouldn't it be easier drawing these lines with Epilog? Jul 8, 2015 at 19:45
• Wow! Nice answer. Thanks for the help. Jul 8, 2015 at 19:45
• @David, since you're teaching calculus, think of it this way: ContourPlot[] relies on the intermediate value theorem; if it can't find any sign changes in the function values along a putative contour, then it won't draw the contour. So, if your surface merely touches the $x$-$y$ plane as opposed to crossing it, you'll have a hard time visualizing the contour at $z=0$. Jul 8, 2015 at 23:03
• @yohbs: Yes, I could have used Epilog. But they won't always be lines. I've added an example to my original post explaining why. This is going to be visually helpful to students when they are trying to determine critical values for optimization. Jul 9, 2015 at 0:57