2
$\begingroup$

I want to plot a complex matrix, i.e., a matrix with complex number entries. I want the matrix to be plotted as DiscretePlot3D as shown in the figure (top figure). But, I also want each bar to be colored based on the phase of the complex number (bottom figure). If you want to try it out, here is the matrix data: {{49.409 + 8.47185 I, 43.8837 + 0.085242 I, 36.0617 + 13.6225 I, 0. + 0. I}, {43.8837 + 0.085242 I, 12.6563 - 21.9037 I, 0. + 0. I, -36.0617 - 13.6225 I}, {36.0617 + 13.6225 I, 0. + 0. I, -12.6563 + 21.9037 I, -43.8837 - 0.085242 I}, {0. + 0. I, -36.0617 - 13.6225 I, -43.8837 - 0.085242 I, -49.409 - 8.47185 I}} Magnitude of complex entries of the matrixPhase based colors of the complex entries of the matrix

$\endgroup$
5
  • $\begingroup$ What is meaning of the height or color? $\endgroup$
    – cvgmt
    Feb 22, 2023 at 0:08
  • $\begingroup$ I am sorry. The height of the bars in the blue 3D plot are the absolute values of complex number. The color in the bottom figure is the argument (phase) of the complex number. I would like to make a 3D plot like shown in top figure and color each bar with the color shown in the bottom plot. $\endgroup$ Feb 22, 2023 at 0:29
  • $\begingroup$ Can you create the first plot? Can you create the second plot? It's not very clear what it is that you cannot solve. $\endgroup$
    – bmf
    Feb 22, 2023 at 1:49
  • $\begingroup$ I can create both the plots. However, what I want is to create a 3D plot like the first one but color it using colors taken from the second plot. So Basically two different sets of data to specify height and color. $\endgroup$ Feb 22, 2023 at 2:21
  • $\begingroup$ Welcome to the Mathematica Stack Exchange. The introductory book written by the inventor is a good learning resource. There is a fast intro for math students as well as a fast intro for programmers to choose from. $\endgroup$
    – Syed
    Feb 22, 2023 at 3:44

3 Answers 3

5
$\begingroup$
clist = {{49.409 + 8.47185 I, 43.8837 + 0.085242 I, 
   36.0617 + 13.6225 I, 0. + 0. I}, {43.8837 + 0.085242 I, 
   12.6563 - 21.9037 I, 
   0. + 0. I, -36.0617 - 13.6225 I}, {36.0617 + 13.6225 I, 
   0. + 0. I, -12.6563 + 21.9037 I, -43.8837 - 0.085242 I}, {0. + 
    0. I, -36.0617 - 13.6225 I, -43.8837 - 0.085242 I, -49.409 - 
    8.47185 I}};

cdata = Flatten[#, 1] &@
  MapIndexed[{Sequence @@ #2, Sequence @@ AbsArg[#1]} &, clist, {2}];

Graphics3D[{Opacity[0.3]
  , {Hue[#[[4]]]
     , Cuboid[{#[[1]] - 0.5, #[[2]] - 0.5, 0}
      , {#[[1]] + 0.5, #[[2]] + 0.5, #[[3]]}
      ]} & /@ cdata
  }
 , Axes -> True
 , Boxed -> True
 , BoxRatios -> {1, 1, 1}
 ]

enter image description here

$\endgroup$
1
  • $\begingroup$ For rescaling the Hue, you can try: Hue[Rescale[Mod[#[[4]], 2 \[Pi]], {0, 2 \[Pi]}]] and please let me know if it suits better. If so, I will update the answer. $\endgroup$
    – Syed
    Feb 22, 2023 at 5:41
5
$\begingroup$

Not perfect, but perhaps will get you started.

stillneedswork

Code:

datatable = complexlist;
options = Sequence[
   ColorFunction -> "TemperatureMap",
   PlotRangePadding -> None,
   Frame -> False,
   ImagePadding -> None,
   ImageSize -> 300,
   Mesh -> None];
texture1 = ListDensityPlot[
   Arg /@ complexlist,
   Mesh -> Full,
   ColorFunction -> "Rainbow",
   ImageSize -> 300,
   Frame -> False];
lstplt1 = ListPlot3D[
   Abs[complexlist],
   InterpolationOrder -> 0,
   Mesh -> Full,
   BoxRatios -> 1,
   PlotStyle -> Texture[texture1],
   Filling -> Axis,
   FillingStyle -> "Rainbow",
   ImageSize -> 300];
Grid@{{texture1, lstplt1}}

Data

complexlist = {{49.409 + 8.47185 I, 43.8837 + 0.085242 I, 
    36.0617 + 13.6225 I, 0. + 0. I}, {43.8837 + 0.085242 I, 
    12.6563 - 21.9037 I, 
    0. + 0. I, -36.0617 - 13.6225 I}, {36.0617 + 13.6225 I, 
    0. + 0. I, -12.6563 + 21.9037 I, -43.8837 - 0.085242 I}, {0. + 
     0. I, -36.0617 - 13.6225 I, -43.8837 - 0.085242 I, -49.409 - 
     8.47185 I}};
$\endgroup$
1
  • 1
    $\begingroup$ Thank you so much for the code. The vertical bars I got are all opaque and purple with only their top surface. However, what I am trying to draw is a simpler plot. I need slightly transparent bars with same color as obtained using texture. I am trying to modify the code but you are really good at this. I will try to edit it to get what I need. Thank you so much. $\endgroup$ Feb 22, 2023 at 3:11
3
$\begingroup$

I define color to approximate the colors in the OP. The range of Arg is -Pi to Pi, so I defined color to use that instead of 0 to 2*Pi.

color=Function[{arg},
   Blend[{RGBColor[0.55,0.7,0.55],RGBColor[0.75,0.8,0.55],RGBColor[0.85,0.75,0.4],RGBColor[0.9,0.6,0.096],RGBColor[0.75,0.2,0.07]},Rescale[arg,{-Pi,Pi}]] 
];
BarLegend[{color,{-Pi,Pi}}]

enter image description here

Then based on the solution from syed we have my solution below. I avoid using slots such as #4 since novices are not familiar with them.

clist={{49.409+8.47185 I,43.8837+0.085242 I,36.0617+13.6225 I,0.+0. I},{43.8837+0.085242 I,12.6563-21.9037 I,0.+0. I,-36.0617-13.6225 I},{36.0617+13.6225 I,0.+0. I,-12.6563+21.9037 I,-43.8837-0.085242 I},{0.+0. I,-36.0617-13.6225 I,-43.8837-0.085242 I,-49.409-8.47185 I}};
makeData=Function[{z,position},{Sequence@@position,Sequence@@AbsArg[z]}];
cdata = Flatten[MapIndexed[makeData, clist, {2}], 1];
makeCuboid=Function[{re,im,abs,arg},{color[arg],Cuboid[{re-0.5,im-0.5,0},{re+0.5,im+0.5,abs}]}];
Graphics3D[{Opacity[0.7],makeCuboid@@@cdata},Axes->True,Boxed->True,BoxRatios->{1,1,1}]

Graphics3D

However, instead of the color scheme above I recommend this.

ArgHue=ResourceFunction["ArgHue"];
BarLegend[{ArgHue,{-Pi,Pi}}]

rainbow graphic

ArgHue above makes it easier for your eye to approximate phase from the color.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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