# How to create a 3D density map of a system of varying number of particles?

I have a time-dependent system of varying number of particles (~100k particles). In fact, each particle represents an interaction in a 3D space with a particular strength. Thus, each particle has (X,Y,Z;w) which is the coordinate plus a weight factor between 0 and 1, showing the strength of interaction in that coordinate. Here http://pho.to/9Ztti I have uploaded 10 real-time snapshots of the system, with particles are represented as reddish small dots; the redder the dot, the stronger the interaction is.

The question is: how one can produce a 3D (spatial) density map of these particles, preferably in Matlab or Origin Pro 9 or ImageJ? Is there a way to, say, take the average of these images based on the red-color intensity in ImageJ?

Since I have the numerical data for particles (X,Y,Z;w) I can analyze those data in other software as well. So, you are welcome to suggest any other analytical approach/software

• well, have you tried anything so far?
– tel
Jul 17, 2015 at 3:27
• yep; ImajeJ and Origin Pro; both not successful. Jul 17, 2015 at 4:53

R packages misc3d and rgl. The function image3d in misc3d does what you need and is very parametrizable via rgl (change the transparency, the view angle, axes, etc...). I used it with fairly big arrays (~10000000 data points/plots) and it produced great 3D density plots.

Both R (e.g. package biOps) and Matlab (image processing toolbox) have very powerful tools for image analysis if you need to get for example RBG levels in your plots but as far as I understood, you have the 3D arrays containing the interaction values, right?

Matlab proposes similar tools if you prefer Matlab (don't remember the exact functions) over R and both will require a fair amount of RAM as the data must be loaded in the environment.

As your system is time dependent you can also create movies fairly easily if you wish so (e.g. rgl's movie3d function).

Here a quick example of a 3D density plot:  • Yep; you're right. I have the arrays of $x$ , $y$ , and $z$, and $w$ for the interactions locations and strength. Jul 19, 2015 at 9:47
• Ok, then it is quite straightforward to make such plots using those functions. Jul 19, 2015 at 10:44
• Well, I installed R , misc3d and rgl packages. But, to use image3d, one needs a "3 dimensional data array". My collection of $(X,Y,Z)$s makes a 2D array. Should I convert it to 3D??? and how?? Jul 20, 2015 at 2:34
• @deeep how is a collection of (X,Y,Z) 2D? Jul 20, 2015 at 20:59
• Well, here is the collection of my $(X,Y,Z)$s: $$x_{1@t1} \quad y_{1@t1} \quad z_{1@t1}$$ $$x_{2@t1} \quad y_{2@t1} \quad z_{2@t1}$$ $$...$$ $$x_{N@t1} \quad y_{N@t1} \quad z_{N@t1}$$ $$--------------$$ $$x_{1@t2} \quad y_{1@t2} \quad z_{1@t2}$$ $$x_{2@t2} \quad y_{2@t2} \quad z_{2@t2}$$ $$...$$ $$x_{M@t2} \quad y_{M@t2} \quad z_{M@t2}$$ $$--------------$$ $$.$$ $$.$$ Where $t1$ refers to time 1, $t2$ time 2, etc. Also $N$ is the number of particles (=interactions) at time 1, $M$ number of particles at time 2, and so on. To me this is a 2D array, like in Matlab. Jul 21, 2015 at 11:13

One approach: fit a kernel density estimator to the observed coordinates $\{ (X_i,Y_i,Z_i) \}$ and color by density: https://stackoverflow.com/questions/25286811/how-to-plot-a-3d-density-map-in-python-with-matplotlib/25354417#25354417

Incorporating the weights $w$ of each observation is a bit trickier, but there's code to do this: https://stackoverflow.com/questions/27623919/weighted-gaussian-kernel-density-estimation-in-python/27623920#27623920 , which you can swap in instead of stats.gaussian_kde.

Trying to analyze that much data in ImageJ seems likely to end in frustration. Matlab is probably a more productive angle. Personally, I would use Python. Specifically, the numpy module. Try looking into the histogramdd function in numpy. It might be able to accomplish what you're after.