2
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ ListDensityPlot3D could be a possibility. $\endgroup$ – yarchik Nov 9 '19 at 21:25
  • $\begingroup$ Thank you. I`m 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] $\endgroup$ – bvl Nov 9 '19 at 22:16
  • $\begingroup$ @andre314 It gives "List" $\endgroup$ – bvl Nov 9 '19 at 22:24
3
$\begingroup$

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

enter image description here

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
$\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.