1

I am encountering a bizarre problem. I'm trying to generate the complex phase plot of the (principal branch of) the square root function by using DensityPlot on the argument of the square root with ColorFunction -> Hue.

Arg[Sqrt[-1]]

gives $\pi/2$ as expected. Then

Hue[Rescale[Arg[Sqrt[-1]], {-π, π}]]

gives Hue[3/4].

However,

DensityPlot[
      Rescale[Arg[Sqrt[x + I y]], {-π, π}], {x, -1, 1}, {y, -1, 1},
      PlotPoints -> 100, ColorFunction -> Hue, Exclusions -> None]

produces

Density plot of argument of square root function

which is clearly painting $-1$ in red.

Is this a bug?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574

1 Answers1

4

First, let's look at what $\arg$ looks like in Mathematica:

Plot3D[Arg[x + I y], {x, -4, 4}, {y, -4, 4}]

phase of a complex number

Note that $\arg$'s codomain here is $(-\pi,\pi]$, and that the branch cut runs along the ray $(-\infty,0)$. Thus, when you use Rescale[x, {-π, π}], values along the negative real axis ($\arg z=\pi$) get mapped to 1, and Hue[1] is of course a nice shade of red.

In this case, you'll want a preliminary application of $\bmod$ to $\arg$, to get results on the interval $[0,2\pi)$ and see the expected color wheel:

DensityPlot[Mod[Arg[x + I y], 2 π], {x, -1, 1}, {y, -1, 1}, ColorFunction -> Hue,
            Exclusions -> None, PlotPoints -> 100]

complex color wheel

Note the conspicuous lack of a Rescale[]. This is due to the setting ColorFunctionScaling being set to True by default, which rescales the values of the function before they are fed to the ColorFunction; thus, Hue[] is only seeing values in $[0,1]$. If you set ColorFunctionScaling -> False, then you do need an explicit Rescale[]:

DensityPlot[Rescale[Mod[Arg[x + I y], 2 π], {0, 2 π}], {x, -1, 1}, {y, -1, 1},
            ColorFunction -> Hue, ColorFunctionScaling -> False,
            Exclusions -> None, PlotPoints -> 100]

which should yield the very same color wheel.

Finally, here is what $\sqrt{z}$ looks like when "domain colored":

DensityPlot[Mod[Arg[Sqrt[x + I y]], 2 π], {x, -1, 1}, {y, -1, 1}, 
            ColorFunction -> Hue, Exclusions -> None, PlotPoints -> 100]

domain coloring of the square root function

Last, but not the least, this previous thread on domain coloring might be of interest.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574