# How can I plot a 2D matrix with this style?

It is possible to plot the matrix like in the image. I'm using

ListPointPlot3D[Abs[amn], PlotRange -> All, Filling -> Axis]


Where amn is the 2D matrix but the result is not near to the image

    amn = {{-5.75339*10^-17 - 7.01058*10^-17 I,
0.00200623 + 0.00484347 I, -0.00897283 - 0.00897283 I,
0.020567 + 0.00851913 I, -0.0274853 - 9.22671*10^-17 I,
0.020567 - 0.00851913 I, -0.00897283 + 0.00897283 I,
0.00200623 - 0.00484347 I, -5.75339*10^-17 -
7.01058*10^-17 I}, {-0.00407975 - 1.51374*10^-16 I,
0.00318289 - 0.00592012 I,
0.00209445 + 0.0139195 I, -0.0182747 - 0.0180699 I,
0.0331421 - 1.57257*10^-16 I, -0.0182747 + 0.0180699 I,
0.00209445 - 0.0139195 I,
0.00318289 + 0.00592012 I, -0.00407975 -
1.51374*10^-16 I}, {0.00592459 - 1.37346*10^-16 I, -0.00710625 +
0.00468769 I, 0.00900641 - 0.0155891 I,
0.00893125 + 0.0378717 I, -0.0646945 - 5.77448*10^-17 I,
0.00893125 - 0.0378717 I,
0.00900641 + 0.0155891 I, -0.00710625 - 0.00468769 I,
0.00592459 - 1.37346*10^-16 I}, {0.0290561 +
7.6544*10^-17 I, -0.00623189 - 0.0356728 I, -0.0573817 +
0.034597 I, 0.111297 - 0.00957322 I, 0.323006 + 3.09492*10^-17 I,
0.111297 + 0.00957322 I, -0.0573817 - 0.034597 I, -0.00623189 +
0.0356728 I,
0.0290561 + 7.6544*10^-17 I}, {7.97973*10^-17 - 1.03917*10^-17 I,
0.00362693 + 0.00875619 I,
0.0211843 + 0.0211843 I, -0.0976489 - 0.0404475 I,
0.570093 + 2.32563*10^-18 I, -0.0976489 + 0.0404475 I,
0.0211843 - 0.0211843 I, 0.00362693 - 0.00875619 I,
7.97973*10^-17 - 1.03917*10^-17 I}, {-0.0290561 -
1.42283*10^-17 I, -0.0208179 - 0.0296311 I, 0.034597 - 0.0573817 I,
0.0719297 + 0.0854683 I, 0.323006 + 4.23599*10^-17 I,
0.0719297 - 0.0854683 I,
0.034597 + 0.0573817 I, -0.0208179 + 0.0296311 I, -0.0290561 -
1.42283*10^-17 I}, {-0.00592459 + 1.64616*10^-18 I,
0.00833958 - 0.00171018 I, -0.0155891 + 0.00900641 I,
0.0330947 - 0.020464 I, -0.0646945 - 5.90368*10^-17 I,
0.0330947 + 0.020464 I, -0.0155891 - 0.00900641 I,
0.00833958 + 0.00171018 I, -0.00592459 +
1.64616*10^-18 I}, {0.00407975 - 3.94513*10^-17 I, -0.0064368 -
0.00193552 I, 0.0139195 + 0.00209445 I, -0.0256995 - 0.00014478 I,
0.0331421 - 6.04677*10^-18 I, -0.0256995 + 0.00014478 I,
0.0139195 - 0.00209445 I, -0.0064368 + 0.00193552 I,
0.00407975 - 3.94513*10^-17 I}, {-5.75339*10^-17 - 7.01058*10^-17 I,
0.00200623 + 0.00484347 I, -0.00897283 - 0.00897283 I,
0.020567 + 0.00851913 I, -0.0274853 - 9.22671*10^-17 I,
0.020567 - 0.00851913 I, -0.00897283 + 0.00897283 I,
0.00200623 - 0.00484347 I, -5.75339*10^-17 - 7.01058*10^-17 I}}


The values are complex numbers basically, can be use any complex values, the requirement is a complex 2d matrix

• try ListPlot3D instead of ListPointPlot3D? May 1, 2021 at 23:05
• The problem is that I need that kind of pyramidal shape over the matrix entry, ListPlot3d produces a continuous surface May 2, 2021 at 19:05

To do this you might have to add extra values to your matrix, essentially to "pin down" the values of ListPlot3D to 0 between your "actual" matrix values. We can do that as follows:

mRiffle0[m_?MatrixQ] :=
Riffle[Riffle[#, 0, {1, -1, 2}] & /@
m, {ConstantArray[0, 1 + 2*Dimensions[m][[2]]]}, {1, -1, 2}]

ListPlot3D[mRiffle0[Abs[amn]], PlotRange -> Full, Mesh -> Full, DataRange -> {{-4.5, 4.5}, {-4.5, 4.5}}]


(I'm not sure if I got the DataRange quite right, but you can play with it if you want. You can also change PlotStyle, MeshStyle, and Lighting to make it even closer!)

At first we use InterpolationOrder -> 0 to draw the piecewise function.

data = Abs[amn];
fig = ListPlot3D[data, PlotRange -> All, InterpolationOrder -> 0,
Mesh -> None, BoundaryStyle -> None, AspectRatio -> Automatic,
Boxed -> False, Axes -> None];


Then we replace all the space rectangles to pyramids by

pts = {{0, 0, 2}, {1, 0, 2}, {1, 1, 2}, {0, 1, 2}};
Graphics3D[{{Opacity[.8], Polygon[pts]}, {FaceForm[White],
EdgeForm[Black], Lighting -> {{"Ambient", White}},
Pyramid[Append[ScalingTransform[{1, 1, 0}]@pts, Mean[pts]]]}},
Boxed -> False]


That is

Normal[fig] /.
Polygon[a___] :> {FaceForm[White], EdgeForm[Black],
Lighting -> {{"Ambient", White}},
Pyramid[Append[ScalingTransform[{1, 1, 0}]@First@Polygon[a],
Mean[First@Polygon[a]]]]}