Let $z \in \mathbb C$ be an arbitrary complex number. Call it

  • Red, if $\Im(z^7) > 0$
  • Blue, if $\Im(z^7) < 0$
  • Gray, if $\Im(z^7) = 0$.

I want to make a plot in which the red, blue and gray regions of the complex plane are painted in the appropriate color. I have the following helper function:

proc[f_, r_] := ComplexContourPlot[f, {z, 2},
  Contours -> r, ContourShading -> {LightBlue, LightPink}];

The naïve way to use this function is

proc[Im[z^7], {0}]

This does not work as nicely as one would hope. The plot is distorted near the origin due to numerical stability issues in the calculation of $\Im(z^7)$ for very small $z$.

Another attempt would be

r = Range[-Pi, Pi, Pi/7];
proc[Arg[z], r]

This almost works, but not quite. The negative real axis is not painted correctly. This behavior is not unexpected, because Arg[z] is discontinuous at the negative real axis. But it is still annoying.

One rather ugly way to make this work is

p1 = proc[Arg[z], r];
p2 = proc[Arg[-z], {0}];
Show[p2, p1]

Is there anything less egregious than this that will still work?

  • 1
    $\begingroup$ Is cranking up PlotPoints not an option? I don't have MM 12, so I can't use ComplexContourPlot, but using ContourPlot[Im[(x + I y)^7], {x, -2, 2}, {y, -2, 2}, PlotPoints -> 100] in MM 11 seems to give a reasonable result. $\endgroup$ May 14, 2020 at 18:02
  • 2
    $\begingroup$ Building off @Michael's proposal, here's one way to color it: ContourPlot[Im[(x + I y)^7], {x, -2, 2}, {y, -2, 2}, ColorFunction -> (Blend[{Blue, Gray, Red}, LogisticSigmoid[10 #]] &), ColorFunctionScaling -> False, PlotPoints -> 100, PlotRange -> All] $\endgroup$ May 14, 2020 at 18:11
  • $\begingroup$ @MichaelSeifert That did the trick, thanks! $\endgroup$
    – pyon
    May 14, 2020 at 18:19

1 Answer 1


If processing time is not a concern, the option PlotPoints can be used to force Mathematica to perform more sampling of the function being plotted.

ComplexContourPlot[f, {z, 2},  Contours -> r, 
 ContourShading -> {LightBlue, LightPink}, PlotPoints->100]

(Please note: I have not tried this code, as I do not have MM 12. If it does not work, please let me know.)

  • $\begingroup$ It does work, thanks! $\endgroup$
    – pyon
    May 14, 2020 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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