Point Density SurfaceΒΆ
Surfaces of constant density within a point cloud are created using the cloud object method valsurf. The relden argument is the relative density of the surface 3D contour within the cloud.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm,colors,colormaps,patches
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, relden,cmap = 1.2, 3, 0.3, 'YlGnBu_r'
cloudObj = ptc.Point3DCloud(drez,cmap=cmap,domain=domain)
cloudObj.map_vals_from_sampdens(input_coor,pdg)
cloudObj.map_cmap_from_cloudvals()
surface = cloudObj.valsurf( relden )
surface.triangulate(2)
# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(10,4))
# ....................
title = 'sample density surface'
fig.text(0.27,0.01,str(surface),ha='center',va='bottom',fontsize='small')
fig.text(.27,0.92,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.add_collection3d(surface.shade(flat=False).hilite(flat=False))
s3d.add_boxCorner(ax,domain)
denColor = cloudObj._cmap(relden)
denpatch = patches.Patch(label='density = '+str(relden), color=denColor )
ax.legend(handles=[denpatch])
# ....................
fig.text(0.7,0.01,str(cloudObj),ha='center',va='bottom',fontsize='small')
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()
