# Unwanted regions in ContourPlot

I have created a 3D plot and a contour plot for the same (Wigner) function, but as you see the contour plot is not right. It has some "extra" regions in gray color (ovals). What is going wrong? The 3D plot code is

Plot3D[2/((2 + 2/E^8) \[Pi]) (Exp[-2 (4 - 4 x + x^2 + y^2)] +
Exp[-2 (4 + 4 x + x^2 + y^2)] +
2 Exp[-2 (x^2 + y^2)] Cos[8 y]), {x, -4, 4}, {y, -4, 4},
PlotRange -> Full, Exclusions -> None, PlotPoints -> 180,
FaceGrids -> {{0, -1, 0}, {1, 0, 0}, {0, 0, -1}},
FaceGridsStyle -> Directive[Blue, Dotted], Boxed -> False,
BoxRatios -> {1, 1, 1},
AxesLabel -> {"x", "y", "\!$$\*SubscriptBox[\(W$$, $$c$$]\)(x,y)"},
LabelStyle ->   {Bold, Black, FontSize -> 16}]


The contour plot code is

ContourPlot[
2/((2 + 2/E^8) \[Pi]) (Exp[-2 (4 - 4 x + x^2 + y^2)] +
Exp[-2 (4 + 4 x + x^2 + y^2)] +
2 Exp[-2 (x^2 + y^2)] Cos[8 y]), {x, -3, 3}, {y, -3, 3},
PlotLegends -> Automatic,
PlotPoints -> 180]


And here are the figures:

The real contour plot is taken from a textbook (Quantum Optics by Girish Agarwal, Cambridge U Press, 2013, page 80):

To emphasize that it is not a problem for a special case, here I have added another code and figure. You can see the "ugly" ovals are definitely incorrect.

ContourPlot[
1/((2 + 2/E^16) \[Pi])
2 (E^(((2 + 2 I) - x - I y) ((-2 + 2 I) + x - I y)) +
E^(((-2 - 2 I) - x - I y) ((2 - 2 I) + x - I y)) +
E^((-x - I y) (x - I y)) Cos[4 Im[(2 - 2 I) (x + I y)]]), {x, -4,
4}, {y, -4, 4}, PlotLegends -> Automatic,
ColorFunction -> "Rainbow", FrameLabel -> {"x", "y"}, Frame ->  True,
FrameStyle -> Directive[Black, 18], PlotPoints -> 180,
PlotRange -> All, PlotRangePadding -> 0]


Adding Contours -> Range[-0.35, 0.35, 0.1] + 0.03 to my code generated the following plot, which is better, but another problem happened: the colors in the legend are not as they should be. For example, we have the same color for (-0.12,-0.02) and for (0.28,0.38)

• What if you add PlotRange -> All to ContourPlot[]? Commented Sep 26, 2017 at 5:28
• "from a textbook" - which textbook? If you don't give a citation, that statement is not very useful. Commented Sep 26, 2017 at 15:52
• Quantum Optics by Girish Agarwal, Cambridge U Press, 2013, page 80 Commented Sep 26, 2017 at 17:21
• PlotRange -> All did not work Commented Sep 26, 2017 at 17:22
• does the textbook tell you the values for the contour lines? Commented Sep 26, 2017 at 17:40

It looks normal because if you try to draw the 1D dependence:

Plot[(2/((2 + 2/E^8) \[Pi]) (Exp[-2 (4 - 4 x + x^2 + y^2)] +
Exp[-2 (4 + 4 x + x^2 + y^2)] +
2 Exp[-2 (x^2 + y^2)] Cos[8 y])) /. x -> 0, {y, -3, 3},
PlotRange -> {{0, 3}, All}, AxesLabel -> {Y, Z},
Epilog ->
Inset[Plot[(2/((2 + 2/E^8) \[Pi]) (Exp[-2 (4 - 4 x + x^2 + y^2)] +
Exp[-2 (4 + 4 x + x^2 + y^2)] +
2 Exp[-2 (x^2 + y^2)] Cos[8 y])) /. x -> 0, {y, 1.7, 2.5},
Frame -> True, PlotRange -> {-0.0005, 0.0001}],
Scaled@{0.715, 0.75}]]


Then:

The inset shows the small oscillations of the Z[y] at y>1.5

• I added the real contour plot from a textbook. It shows that something is wrong Commented Sep 26, 2017 at 15:48
• It's likely that the textbook is wrong. Those "extra" contours are contours of zero. The interior of those contours are very slightly negative. Try adding Contours->{0} to see that. And write a note to the textbook author.
– JimB
Commented Sep 26, 2017 at 16:03
• @JimB - it isn't necessarily that the textbook is wrong, just that they made a decision not to put a contour at 0. This is a reasonable choice with decaying oscillatory functions. It's possible the authors list the contour values in the figure caption. Commented Sep 26, 2017 at 16:06
• @JasonB. No disagreement with your comment. It is the color scheme plus the contour lines that makes things appear more extreme than they are. I was also using the more binary choice of "right" and "wrong" implied by the OP.
– JimB
Commented Sep 26, 2017 at 16:17
• @JasonB. You should write-up your answer about not having a contour at zero. Using Contours -> {-0.4, -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3} (which avoids the zero contour) seems to reconcile the issue.
– JimB
Commented Sep 26, 2017 at 16:27