# White Lines in Contour Plot and 3D Plot

This is a follow up question to the original question here (has a solution).

I am plotting another different total potentials and for this particular case the repulsive potential is a rectangle (open at one end - please refer to the contour plot attached below).

Problem: I am getting white lines in the contour and 3D plots that seem to be coming from the sides of the rectangle. Is there a way of avoiding or getting rid off these white lines?

Given below is the code and the two plots.

(*Assignments*)
xmax = 130;
ymax = 130;
z = 3;
p[1] = 65; p[2] = 125;
a[1, 1] = 58; b[1, 1] = 130;
a[1, 2] = 58; b[1, 2] = 105;
a[2, 1] = 72; b[2, 1] = 130;
a[2, 2] = 72; b[2, 2] = 105;
a[3, 1] = 72; b[3, 1] = 130;
a[3, 2] = 58; b[3, 2] = 130;

(*Functions*)
V = 0.5*((x - p[1])^2 + (y - p[2])^2);
Table[q[k, 1] = (a[k, 2] - a[k, 1])/((a[k, 2] - a[k, 1])^2 + (b[k, 2] - b[k, 1])^2), {k, 1, z}];
Table[q[k, 2] = (b[k, 2] - b[k, 1])/((a[k, 2] - a[k, 1])^2 + (b[k, 2] - b[k, 1])^2), {k, 1, z}];
Table[l[k] = (x - a[k, 1])*q[k, 1] + (y - b[k, 1])*q[k, 2], {k, 1, z}];
Table[m[k] = Piecewise[{{0.001, l[k] < 0}, {l[k], 0 <= l[k] <= 1}, {1, l[k] > 1}}], {k, 1, z}];
Table[c[k] = a[k, 1] + m[k] (a[k, 2] - a[k, 1]), {k, 1, z}];
Table[d[k] = b[k, 1] + m[k] (b[k, 2] - b[k, 1]), {k, 1, z}];
Table[RO[k] = 0.5*((x - c[k])^2 + (y - d[k])^2), {k, 1, z}];
Table[SO[k] = Piecewise[{{0.001, RO[k] <= 0}, {RO[k], RO[k] > 0}}], {k, 1, z}];

(*Parameter: User-defined*)
Table[delta[k] = 10000, {k, 1, z}];

(*We need to plot L*)
L = V + Sum[delta[k]/SO[k], {k, 1, z}];

(*Contour plot*)
ContourPlot[L, {x, 0, xmax}, {y, 0, ymax + 1}, Contours -> 50, ColorFunction -> Function[{x, y, z}, Hue[x]]]

(*3D plot*)
Plot3D[L, {x, 0, xmax}, {y, 0, ymax + 1}, ColorFunction -> Function[{x, y, z}, Hue[z]], Mesh -> None, ClippingStyle -> {Blue, Red}]


I had a look at an earlier post (see this) but it seems that my problem is a bit different from this post.

Thanks, Jack

Using the option Exclusions->None fixes the issue in both plots:

ContourPlot[L, {x, 0, xmax}, {y, 0, ymax + 1}, Contours -> 50,
ColorFunction -> Function[{x, y, z}, Hue[x]], Exclusions -> None]


Plot3D[L, {x, 0, xmax}, {y, 0, ymax + 1},
ColorFunction -> Function[{x, y, z}, Hue[z]], Mesh -> None,
ClippingStyle -> {Blue, Red}, Exclusions -> None]


• Thank you. Really appreciated.
– Jack
Apr 3, 2015 at 16:52
• @Jack, glad i could help. Welcome to mma.se.
– kglr
Apr 3, 2015 at 16:53
• Does anyone know why these white lines happen? I get them when using ContourPlot on Re@(complex function). Is Mathematica assuming there will be branch cuts? @kglr
– Max
Apr 14, 2018 at 18:45
• @Max, hope this helps: Exclusions >> Details says (1) Exclusions->Automatic is effectively equivalent to Exclusions->True if \$PerformanceGoal is "Quality", and to Exclusions->None otherwise and (2) Exclusions->True excludes all subregions where discontinuities are found in functions being plotted. The discontinuities can involve either finite or infinite jumps in function values.
– kglr
Apr 14, 2018 at 19:08
• @kglr Hm that doesn't seem to explain my case. I notice a white line appears for ContourPlot[Re@Exp[ ArcTan[x, y]], {x, -1, 1}, {y, -1, 1}] but not ContourPlot[Cos[ ArcTan[x, y]], {x, -1, 1}, {y, -1, 1}]. The only difference between these is the first is Re[complex] while the second is just Real.
– Max
Apr 14, 2018 at 19:35