I have data that is in four columns. The x y and z are just the coordinates and the fourth is my data. This is not a function. This is electron density in a copper cell and I'm trying to display it in a way that makes sense. Any help would be appreciated. I was semi-successful in gnuplot but it was hard to see and I could only specify certain boundaries. using ($1:$2:($4>0 && $4<2 ? $3/0) This might be slightly wrong, but you get the picture. I was saying to only plot z if the data was between certain bounds. There must be a better way and I need your help. Thanks. Here is the structure.

enter image description here

  • $\begingroup$ Have you tried ListContourPlot3D? By the way, your title is misleading: this is a 3D density, that is, a density over a three-dimensional region. $\endgroup$
    – user484
    Commented Mar 19, 2014 at 4:40
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/questions/19575/… $\endgroup$
    – Michael E2
    Commented Mar 19, 2014 at 4:40

2 Answers 2

dens = Table[{x, y, z, E^-Norm[{x, y, z}]^2}, {x, -1, 1, .1}, {y, -1,  1, .1}, {z, 0, 1, .1}]; 
ListContourPlot3D[Flatten[dens, 2], 
 Contours -> Range[.1, .3, .03], Mesh -> None, 
 ContourStyle -> Opacity[.3], BoundaryStyle -> None, 
 ColorFunction -> "TemperatureMap", BoxRatios -> {1, 1, 1/2}, 
 Boxed -> False, Axes -> False]

Mathematica graphics

  • $\begingroup$ I think BoxRatios->Automatic is more useful generally, unless you want to force some particular ratios. Automatic makes scales of all directions the same, so that e.g. for a sphere you'll get a sphere not an ellipsoid, without having to think what your PlotRange is. $\endgroup$
    – Ruslan
    Commented Dec 9, 2017 at 9:04

Starting with Mathematica 11, you can use ListDensityPlot3D function. Taking Dr. belisarius's example data, here's the plot of it:

dens = Table[{x, y, z, E^-Norm[{x, y, z}]^2}, {x, -1, 1, .1}, {y, -1, 1, .1}, {z, 0, 1, .1}];
ListDensityPlot3D[Flatten[dens, 2], PlotRange -> All, BoxRatios -> Automatic]

Output of ListDensityPlot3D

Or, if you want it to look more like a density cloud instead of jelly, you can tweak some options:

ListDensityPlot3D[Flatten[dens, 2], PlotRange -> All, BoxRatios -> Automatic, 
 ColorFunction -> (RGBColor[0.95, 0.6, 0.15] &), OpacityFunction -> (#^4/5 &)]

enter image description here


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.