2
$\begingroup$

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

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

1 Answer 1

3
$\begingroup$

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

$\endgroup$
2
  • 1
    $\begingroup$ @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. $\endgroup$
    – Michael E2
    Aug 6, 2017 at 20:20
  • 1
    $\begingroup$ Exclusions -> {x^2 + y^2 == 0.0001} also works. $\endgroup$
    – Michael E2
    Aug 6, 2017 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.