# Plotting a Complex Valued Function

Suppose that a complex valued function f[z]=f[x+i y]=u[x,y]+i v[x,y]. I want to plot3d its real part by coloring it with respect to its imaginary part. For instance, if m and M are the smallest and greatest values of the imaginary part, I want to color the graphic from white to black depending on the value of the imaginary part (m is white, M is black). I would be very glad if you can help me.

• Related: 1), 2). Jun 6, 2013 at 22:53

Since you didn't mention what functions you want to plot, here are some simple ones:

 v[x_, y_] := Cos[x y];
w[x_, y_] := x y;
Plot3D[v[x, y], {x, 0, 1}, {y, 0, 1}, ColorFunction -> Function[{x, y, z}, w[x, y]]]


This works by choosing the ColorFunction to be the function w while the surface is v[x,y], so your original complex-valued function is f[x,y]:=v[x,y]+I w[x,y]. As 0x4A4D points out, there are many ways to proceed: many options for ColorFunctions and many ways to scale these using ColorFunctionScaling to fine tune the appearance of the plot.

• The option ColorFunctionScaling might be interesting for the OP... Jun 6, 2013 at 12:14

Yet another possibility would be to generate a density plot of the imaginary part, and use the resulting plot as a texture for the surface plot of the real part. Here's a demonstration, using $\log(z)$:

tex = Image[DensityPlot[Im[Log[x + I y]], {x, -3, 3}, {y, -3, 3},
AspectRatio -> Automatic, ColorFunction -> (GrayLevel[1 - #] &),
Frame -> False, ImagePadding -> None, PlotPoints -> 45,
PlotRange -> All, PlotRangePadding -> None],
ImageResolution -> 144];

Plot3D[Re[Log[x + I y]], {x, -3, 3}, {y, -3, 3},
BoundaryStyle -> None, Lighting -> "Neutral", Mesh -> None,
PlotPoints -> 45, PlotStyle -> Texture[tex]]


A nice alternative you might want to consider is ColorFunction -> ColorData[{"GrayTones", "Reverse"}].