Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Get the coordinates of densest point

I'm using numpy and scipy to generate a density plot from 3D coordinate information. I can generate a density plot of the data successfully by generating a KDE with the following code

xyz = np.vstack([x,y,z])
kde = stats.gaussian_kde(xyz)
density = kde(xyz)

But how can I use this information to find the coordinates that associate with the 3D point of greatest density?

I've tried

max(density)

which returns a value that I can then find the index of with

density.argmax(axis=0)

but then I hit a blank as I can't seem to use that index to grab the associated coordinates from xyz and I'm unsure if this is the right approach.

like image 703
stoves Avatar asked Feb 12 '26 15:02

stoves


1 Answers

From here, I can use

xyz.T[np.argmax(density)]

to return the 3D coordinates of the densest point in my data

like image 178
stoves Avatar answered Feb 14 '26 05:02

stoves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!