# How to overlap ContourPlots

I have the following functions, which are

x^2 - y^2


and

2 x y


of two variables which represent the real and imaginary part of a complex function $f(z)$. I want to show that the contour lines of the two function intersect perpendicularly. I have the two ContourPlot

cp1 = ContourPlot[x^2 - y^2, {x, -10, 10}, {y, -10, 10},
Contours -> 20,
PlotLegends -> Automatic, ColorFunction -> "Rainbow"];
cp2 = ContourPlot[2 x y, {x, -10, 10}, {y, -10, 10}, Contours -> 20,
PlotLegends -> Automatic, ColorFunction -> "Rainbow"];


What I would like to do is to overlap the two plots keeping the color between the contour lines, but with opacity so that I can see the contours below intersecting normally the contours above.

I partially achieved this result with:

cp1 = ContourPlot[x^2 - y^2, {x, -10, 10}, {y, -10, 10},
Contours -> 20,
PlotLegends -> Automatic, ColorFunction -> "Rainbow"];
cp2 = ContourPlot[2 x y, {x, -10, 10}, {y, -10, 10},
Mesh -> None,

ColorFunction -> Function[f, Opacity[.5, ColorData["Rainbow"][f]]],
Contours -> 20,
PlotLegends -> Automatic
];
Show[cp1, cp2]


but as you can notice there's a strange grid below the fist plot...

# EDIT (completness):

I'm using mathematica 11.1.0.0

• No strange grid for me. I'm using version 11.1. What are you using?
– Hugh
Aug 6, 2017 at 19:12
• 11.1 as well... Can't understand what it is... Aug 6, 2017 at 19:16
• Also for me it works perfectly (V 10)
– eldo
Aug 6, 2017 at 19:22
• This works for me: Show[cp1, cp2 /. EdgeForm[] -> EdgeForm[Directive[Opacity[0]]]]. Does it for you? Aug 6, 2017 at 19:38
• I posted an answer, but maybe someone will fix cp1. (The same trick does not work on it.) Aug 6, 2017 at 20:10

Try

Show[cp1, cp2 /. EdgeForm[] -> EdgeForm[Opacity[0]]]


The lines in the OP come from the edges of the polygons forming the contour shading. The above trick makes them invisible.

(The OP said this is acceptable, but I see faint, dark lines from the edges of the polygons of cp1.)

• @opisthofulax Try adding the option MaxRecursion -> 3 to the ContourPlot[] for cp1. Stationary points are singular points for ContourPlot, in that the contour through one is usually not a single, simple curve. Normally you can't fix it, but you can make it smaller. Increasing PlotPoints and/or MaxRecursion is how you do might that. Aug 6, 2017 at 20:20
• Exclusions -> {x^2 + y^2 == 0.0001} also works. Aug 6, 2017 at 20:25