1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ MatrixPlot[ Hue[Abs@#, (Arg[#] + Pi)/2/Pi] & /@ # & /@ RandomComplex[1 + I, {5, 5}]]? $\endgroup$ – kglr May 19 '18 at 9:06
  • $\begingroup$ 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.) $\endgroup$ – Henrik Schumacher May 19 '18 at 9:06
0
$\begingroup$
SeedRandom[1]
a = RandomComplex[1 + I, {5, 5}];

The argument array in ArrayPlot[array] can contain color directives as mentioned in ArrayPlot >> Details and Options enter image description here

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}]

enter image description here

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.