Point Density Cloud

../../_images/pntdencloud.png

The density value of each sample is represented using a normal distribution from the sample coordinate. The distribution controlled by the pdg argument. For this example of a random distribution of sample positions, pdg is 1.2.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm,colors,colormaps
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc

# 1. Get data to examine ...........................................
npnts,seed,domain = 50, 6, [ [-7,6], [5,30], [0,50] ]
np.random.seed(seed)
xc = np.random.uniform(*domain[0], npnts)
yc = np.random.uniform(*domain[1], npnts)
zc = np.random.uniform(*domain[2], npnts)
input_coor = np.column_stack((xc,yc,zc))

# 2. Setup and map surface .........................................
pdg, drez, cmap = 1.2 , 3, 'YlGnBu_r'

cloudObj = ptc.Point3DCloud(drez,cmap=cmap,domain=domain)
cloudObj.map_vals_from_sampdens(input_coor,pdg)
cloudObj.map_cmap_from_cloudvals() 

# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(10,4))
fig.text(0.7,0.01,str(cloudObj),ha='center',va='bottom',fontsize='small')
# ....................
title = 'samples ({})'.format(npnts)
fig.text(.27,0.9,title,ha='center')
ax = fig.add_subplot(121, projection='3d', aspect='equal')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],  
    xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
ax.scatter(*input_coor.T, s=50, color=colormaps[cmap](.5) ,edgecolor='k')
s3d.add_boxCorner(ax,domain)
# ....................
title = 'sample density cloud ( {:.2f} )'.format(pdg)
fig.text(.7,0.92,title,ha='center')
ax = fig.add_subplot(122, projection='3d', aspect='equal')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],  
    xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
cloudObj.add_to3d(ax,.3,span=.35)
s3d.add_boxCorner(ax,domain)
scmp = cloudObj.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.7, pad=.1 )
cbar.set_label('sample density', rotation=270, labelpad = 15)
# ....................
fig.tight_layout(pad=3)
plt.show()