# 3D plot of a heat distribution in a cube

I have a .csv file with temperature values in the nodes of the cube. The cube size is 100х100х100 (.csv file contains 1.000.000 values), while $$0 \leq x,y,z \leq 1$$. How can I plot a 3D heat map of temperature distribution in my cube?

• ListDensityPlot3D could be a possibility. – yarchik Nov 9 '19 at 21:25
• Thank you. Im trying to use this function, but I have an error (not a valid dataset). I think that this is due to the data format in my .csv file. Now my .csv file contains 1m rows and each row has a format: z,y,x,f. I use the following code: data = Import["output.txt" ,"Table"] ListDensityPlot3D[data] – bvl Nov 9 '19 at 22:16
• @andre314 It gives "List" – bvl Nov 9 '19 at 22:24

Since ListDensityPlot3D assumes its data is in the format of {x, y, z, f}, and this data is in the form {z, y, x, f}, we need to change the order of the elements.

data = Import["data.csv", "CSV"];
ListDensityPlot3D[data /. {z_, y_, x_, f_} :> {x, y, z, f}]


For example

data = {#3, #2, #1, 1/Norm[{##}]} & @@@ Tuples[Range[0.01, 1, 0.1], 3];
ListDensityPlot3D[data /. {z_, y_, x_, f_} :> {x, y, z, f}]


And if you're using a version before 10.2, you can make an animation of rising through each z slice.

Export["data.csv", {#3, #2, #1, 1/Norm[{##}]} & @@@ Tuples[Range[0.01, 1, 0.01], 3]];
data = Import["data.csv", "CSV"];
zdata = GatherBy[data, First];
ListDensityPlot[
#1 /. {z_, y_, x_, f_} :> {x, y, f},
FrameLabel -> {"x", "y"},
PlotLabel -> "z = " <> ToString[0.01 First@#2],
BaseStyle -> 11,
PlotLegends -> Automatic
] &~MapIndexed~zdata // ListAnimate
`