Plot a complex function in Mathematica

Simon picture Simon · Mar 22, 2011 · Viewed 19.5k times · Source

How can I make a Mathematica graphics that copies the behaviour of complex_plot in sage? i.e.

... takes a complex function of one variable, and plots output of the function over the specified xrange and yrange as demonstrated below. The magnitude of the output is indicated by the brightness (with zero being black and infinity being white) while the argument is represented by the hue (with red being positive real, and increasing through orange, yellow, ... as the argument increases).

Here's an example (stolen from M. Hampton of Neutral Drifts) of the zeta function with overlayed contours of absolute value:

zeta function complex_plot

In the Mathematica documentation page Functions Of Complex Variables it says that you can visualize complex functions using ContourPlot and DensityPlot "potentially coloring by phase". But the problem is in both types of plots, ColorFunction only takes a single variable equal to the contour or density at the point - so it seems impossible to make it colour the phase/argument while plotting the absolute value. Note that this is not a problem with Plot3D where all 3 parameters (x,y,z) get passed to ColorFunction.

I know that there are other ways to visualize complex functions - such as the "neat example" in the Plot3D docs, but that's not what I want.

Also, I do have one solution below (that has actually been used to generate some graphics used in Wikipedia), but it defines a fairly low level function, and I think that it should be possible with a high level function like ContourPlot or DensityPlot. Not that this should stop you from giving your favourite approach that uses a lower level construction!


Edit: There were some nice articles by Michael Trott in the Mathematica journal on:
Visualizing Riemann surfaces of algebraic functions, IIa, IIb, IIc, IId.
Visualizing Riemann surfaces demo.
The Return of Riemann surfaces (updates for Mma v6)

Of course, Michael Trott wrote the Mathematica guide books, which contain many beautiful graphics, but seem to have fallen behind the accelerated Mathematica release schedule!

Answer

Brett Champion picture Brett Champion · Mar 22, 2011

Here's my attempt. I winged the color function a bit.

ParametricPlot[
 (*just need a vis function that will allow x and y to be in the color function*)
 {x, y}, {x, -6, 3}, {y, -3, 3},

 (*color and mesh functions don't trigger refinement, so just use a big grid*)
 PlotPoints -> 50, MaxRecursion -> 0, Mesh -> 50,

 (*turn off scaling so we can do computations with the actual complex values*)
 ColorFunctionScaling -> False,

 ColorFunction -> (Hue[
     (*hue according to argument, with shift so arg(z)==0 is red*)
     Rescale[Arg[Zeta[# + I #2]], {-Pi, Pi}, {0, 1} + 0.5], 1,

     (*fudge brightness a bit: 
       0.1 keeps things from getting too dark, 
       2 forces some actual bright areas*)
     Rescale[Log[Abs[Zeta[# + I #2]]], {-Infinity, Infinity}, {0.1, 2}]] &),

 (*mesh lines according to magnitude, scaled to avoid the pole at z=1*)
 MeshFunctions -> {Log[Abs[Zeta[#1 + I #2]]] &},

 (*turn off axes, because I don't like them with frames*)
 Axes -> False
 ]

complex plot

I haven't thought of a good way to get the mesh lines to vary in color. Easiest is probably to just generate them with ContourPlot instead of MeshFunctions.