# I have a (4,4,4) dimensional array which are the distribution values. The x, y and z axis range are given. Can you plot 3d heatmap?

{{{0.635235, 0.754568, 0.949016, 1.10997}, {0.659123, 0.782124,
0.982538, 1.14847}, {0.684566, 0.811553, 1.01847,
1.18985}, {0.698054, 0.827206, 1.03767, 1.21202}}, {{0.747369,
0.883016, 1.10377, 1.28631}, {0.776108, 0.916557, 1.14522,
1.33441}, {0.806712, 0.952372, 1.18963, 1.38608}, {0.822933,
0.971418, 1.21336, 1.41377}}, {{0.988875, 1.15951, 1.43676,
1.66569}, {1.02797, 1.20581, 1.49507, 1.7342}, {1.06959, 1.25523,
1.55755, 1.80778}, {1.09164, 1.28151, 1.59091,
1.84718}}, {{1.23819, 1.44482, 1.78025, 2.05699}, {1.28792, 1.5042,
1.85583, 2.14638}, {1.34084, 1.56758, 1.93679, 2.24236}, {1.36887,
1.60126, 1.98001, 2.29374}}}


x = [0. , 1.5, 3. , 4.5, 6. ]

y = [0. , 0.26875, 0.5375 , 0.80625, 1.075 ]

z = [-1.075 , -0.5375, 0. , 0.5375, 1.075 ]

• Your language tags and the format of your data seem to suggest that you are not using Mathematica. Can you convert the code into MMA format? Apr 29, 2022 at 20:06
• Yes, I have been actually using python to plot 3d distribution but didn't got any idea, however, someone plotted this kind of plot in mathematica so seeked help Apr 29, 2022 at 20:12
• You could use ListContourPlot3D or ListDensityPlot3D. Something like ListContourPlot3D[data, DataRange -> MinMax /@ {x, y, z}]. Apr 29, 2022 at 20:59
• Please don't change your question completely after asking it. You just made Daniel Huber's answer make less sense. It's also unclear exactly what you want to do. What "distribution" are you sampling from? Apr 29, 2022 at 21:29

First you need to change your data to an allowed format. E.g. 0.0123 or 123 10^-2. You can do this by entering your data as a string:

str= "[[[ our input data array.... ]]]";


and then make corrections and finally convert it to a MMA expression:

str = StringReplace[str , {"[" -> "{", "]" -> "}", "e" -> " 10^"}];
dat = ToExpression[str];


Finally you may use the function ListSliceDensityPlot3D to get a plot, like e.g.:

ListSliceDensityPlot3D[dat, "CenterPlanes",
DataRange -> {{0, 6}, {0, 1.075}, {-1.075, 1.075}},
PlotLegends -> Rainbow, AxesLabel -> {"X", "Y", "Z"}]


P.S. there seems to be a bug because the legend is plotted twice. I cut it off.

• Thank you for your response and I changed my data too, however, I am looking for contour plot. When I used below code it says that the input data for smooth kernel distribution should be vector or matrix : ContourPlot3D[ Evaluate@PDF[dist, {x, y, z}], {x, 0, 6}, {y, 0, 1}, {z, -1.075, 1.075}, PlotRange -> All, Mesh -> None, MaxRecursion -> 0, PlotPoints -> 160, ContourStyle -> Opacity[0.45], Mesh -> None, ColorFunction -> Function[{x, y, z, f}, ColorData["Rainbow"][z]], AxesLabel -> {x, y, z}] Apr 29, 2022 at 20:26
• @K.Tamang Use ListContourPlot3D on your data directly. Moreover, how did you generate dist? You're omitting a lot of relevant information. Apr 29, 2022 at 21:35