2

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"];

enter image description here

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, 
    (*ContourShading->None, *)

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

enter image description here

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

EDIT (completness):

I'm using mathematica 11.1.0.0

enter image description here

opisthofulax
  • 425
  • 3
  • 15

1 Answers1

3

Try

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

Mathematica graphics

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.)

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • 1
    @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. – Michael E2 Aug 06 '17 at 20:20
  • 1
    Exclusions -> {x^2 + y^2 == 0.0001} also works. – Michael E2 Aug 06 '17 at 20:25