# Extending MatrixPlot to complex-valued matrices

I'm looking to plot a complex-valued matrix in a way similar to MatrixPlot. I know how to map an individual complex number on to a colored swatch: if z is the number in question, just run

Hue[Abs[z], (Arg[z] + pi)/2pi]


In other words, the norm of z is the hue and the phase is the saturation. I would like code which maps a complex-valued matrix onto a matrix of images, as described by the map above, in the same form as one gets from running MatrixPlot on a real-valued matrix. I know GraphicsGrid can kind of do this, but the output is very spread out / ugly.

• MatrixPlot[ Hue[Abs@#, (Arg[#] + Pi)/2/Pi] & /@ # & /@ RandomComplex[1 + I, {5, 5}]]? – kglr May 19 '18 at 9:06
• You can also use ArrayPlot with a user-defined ColorFunction: ArrayPlot[A, ColorFunction -> (z \[Function] Hue[Abs[z], (Arg[z] + Pi)/2 Pi])] (A is the matrix.) – Henrik Schumacher May 19 '18 at 9:06

SeedRandom
a = RandomComplex[1 + I, {5, 5}];


The argument array in ArrayPlot[array] can contain color directives as mentioned in ArrayPlot >> Details and Options So you can use

ap1 = ArrayPlot[Hue[Abs@#, (Arg[#] + Pi)/2/Pi] & /@ # & /@ a, ImageSize -> 300,
FrameTicks -> Automatic];


Alternatively, you can use a as input array and use the options ColorFunction -> (Hue[Abs@#, (Arg[#] + Pi)/2/Pi] &) and ColorFunctionScaling -> False:

ap2 = ArrayPlot[a, ColorFunction -> (Hue[Abs@#, (Arg[#] + Pi)/2/Pi] &),
ColorFunctionScaling -> False, ImageSize -> 300, FrameTicks -> Automatic];

Row[{ap1, ap2}] Although, it is not mentioned in the documentation, the first argument of MatrixPlot can also contain color directives. So, both methods above also work with MatrixPLot:

mp1 = MatrixPlot[Hue[Abs@#, (Arg[#] + Pi)/2/Pi] & /@ # & /@ a, ImageSize -> 300];
mp2 = MatrixPlot[a, ColorFunction -> (Hue[Abs@#, (Arg[#] + Pi)/2/Pi] &),
ColorFunctionScaling -> False, ImageSize -> 300];

Row[{mp1, mp2}]


same picture as above