# 3D Plotting of complex-valued data

I have some matrices which can be exemplified as \begin{align} A=\left( \begin{array}{cccc} 0 & a_{0} x+{\rm i} b_{0}& y & c_{0} y+ {\rm i} d_{0} \\ -a_{0} x+{\rm i} b_{0} & 0 & c_{0} y & d_{0} x y \\ -y & c_{0} y & 0 & b_{0} x \\ -c_{0} y+{\rm i} d_{0} & d_{0} x y+{\rm i} a_{0} & -b_{0} x & 0 \\ \end{array} \right), \end{align} where $$a_{0}, b_{0},c_{0},d_{0}$$ are real-valued parameters. I would like to evaluate the eigenvalues of this matrix, plot their real parts and encode imaginary parts as colors.

Plotting real values of eigenvalues without ColorFunction can be done using

A[a_, b_, c_, d_, x_, y_] := {{0, a x + I b, y, c y + I d },
{-a x + I b, 0 , c y, d x y},
{-y, c y, 0, b x},
{- c y + I d , I  a + d x y, -b x, 0}};
a0val = 0.3;
b0val = 0.2;
c0val = 0.3;
d0val = 0.2;
L = 10;

r1 = Table[{x, y,
Sort[Re[Chop[SetPrecision[
Eigenvalues[A[a0val, b0val, c0val, d0val, x, y]],
10]]]][[1]]}, {x, -2, 2, 4/L}, {y, -2, 2, 4/L}];
r2 = Table[{x, y,
Sort[Re[Chop[SetPrecision[
Eigenvalues[A[a0val, b0val, c0val, d0val, x, y]],
10]]]][[2]]}, {x, -2, 2, 4/L}, {y, -2, 2, 4/L}];
r3 = Table[{x, y,
Sort[Re[Chop[SetPrecision[
Eigenvalues[A[a0val, b0val, c0val, d0val, x, y]],
10]]]][[3]]}, {x, -2, 2, 4/L}, {y, -2, 2, 4/L}];
r4 = Table[{x, y,
Sort[Re[Chop[SetPrecision[
Eigenvalues[A[a0val, b0val, c0val, d0val, x, y]],
10]]]][[4]]}, {x, -2, 2, 4/L}, {y, -2, 2, 4/L}];

g1 = ListPlot3D[Flatten[r1, 1],
PlotStyle -> Directive[Blue, Opacity[0.65]], Mesh -> False];
g2 = ListPlot3D[Flatten[r2, 1],
PlotStyle -> Directive[Gray, Opacity[0.65]], Mesh -> False];
g3 = ListPlot3D[Flatten[r3, 1],
PlotStyle -> Directive[Green, Opacity[0.65]], Mesh -> False];
g4 = ListPlot3D[Flatten[r4, 1],
PlotStyle -> Directive[Red, Opacity[0.65]], Mesh -> False];

plotshow =
Show[g1, g2, g3, g4, PlotRange -> All, AspectRatio -> 1,
Frame -> True]



In my search, I have encountered a similar, but simpler, example here. Their goal was to plot a single function whose imaginary part is known.

How can I implement this way of plotting complex-valued data in my example?

• The eigenvalues are complex valued functions of 4 parameters. This can not be plotted all together because the is not enough space in 3D. The best you can do is to fix 2 parameters and vary the other 2 and e.g. use ComplexPlot3D or Plot3D. Feb 10, 2022 at 13:34
• @DanielHuber, I didn't get your point. Values of $a_{0},b_{0},c_{0},d_{0}$ are fixed. I only want to plot each real part of eigenvalue with the color of its imaginary parts in the $x,y$ space. Thus, for each eigenvalues ($\lambda$) I have a 3D space $(x,y,Re[\lambda])$ with colour coming from $Im[\lambda]$. My presented script already plots Real parts; I just want to figure out how to plot the imaginary parts as ColorFunction to my script. Feb 10, 2022 at 14:00
• Sorry I misunderstood this. Seer my answer below. Feb 10, 2022 at 14:56

Here is an example for the first Table. We first calculate a grid of Imaginary values, then interpolate these values. To use the interpolation we need to rescale it to 0..1 so that we can feed it to Hue:

r1i = Flatten[
Table[{{x, y},
Im[Eigenvalues[
A[a0val, b0val, c0val, d0val, x, y]][[1]]]}, {x, -2, 2,
4/L}, {y, -2, 2, 4/L}], 1];
color = Interpolation[r1i]
mima = MinMax[r1i];
ListPlot3D[Flatten[r1, 1],
ColorFunction -> (Hue[Rescale[color[#1, #2], mima]] &),
ColorFunctionScaling -> False]


• Wonderful! Thank you! Feb 10, 2022 at 15:11