Plotting 3D complex numbers with colours [duplicate]

This question already has an answer here:

I am new to Mathematica and am taking a course in Complex Analysis. I was wondering how to do the following: Plot in 3D (using Plot3D) the real part of f(x+Iy) and then colouring the corresponding 3D plot using some color scheme so that I can see the Imaginary part of f(x+Iy) by looking at the color. Sorry if this question is very elementary. Thanks in advance!

marked as duplicate by J. M. will be back soon♦Oct 3 '16 at 15:28

• You could use the ColorFunction option of Plot3D. For instance: Plot3D[Re[f[x + I y]], {x, -5, 5}, {y, -5, 5}, ColorFunction -> Function[{x, y}, Im[f[x + I y]]]] – JungHwan Min Sep 5 '16 at 18:46
• Take a look at this previous answer: mathematica.stackexchange.com/a/4273/484 – Rahul Sep 5 '16 at 18:46
• FYI, I think it's more common to plot the magnitude of $|f|$ along the $z$-axis, and use $\arg(f)$ to determine the color. The color wheel maps nicely onto the $[0, 2\pi)$ range of the $\arg$ function. – Michael Seifert Sep 5 '16 at 18:59
• I know but for my purposes I would prefer to have it this way. – mtheorylord Sep 5 '16 at 19:11
• If you want a high-quality output of your colored surface, you should consider reading this QA: mathematica.stackexchange.com/q/19110/187 – halirutan Sep 5 '16 at 21:03

f[x_] = x^3;

The min and max of the Im values are

{min, max} = #[
{Im[x + I*y], -3 <= x <= 3, -3 <= y <= 3},
{x, y}][] & /@ {Minimize, Maximize}

(*  {-3, 3}  *)

Legended[
Plot3D[Re[f[x + I*y]],
{x, -3, 3}, {y, -3, 3},
AxesLabel -> (Style[#, 14, Bold] & /@
{"x", "y", "Re[f[x+I*y]]"}),
ColorFunction -> (
ColorData["TemperatureMap"]
[(Im[f[#1 + I*#2]] - min)/(max - min)] &),
ColorFunctionScaling -> False],
BarLegend[{"TemperatureMap", {min, max}},
LegendLabel -> "Im[f[x+I*y]]"]] For comparison purposes to verify accuracy of colors

Plot3D[Im[f[x + I*y]],
{x, -3, 3}, {y, -3, 3},
AxesLabel -> (Style[#, 14, Bold] & /@
{"x", "y", "Im[f[x+I*y]]"})] • Thanks very much. Turned out to be less elementary than I thought. – mtheorylord Sep 6 '16 at 0:12