Unstructured 3-D Coordinate CloudΒΆ
The sample coordinates use a low-discrepancy halton sequence whereas the sample values are based on coordinate position using the implicit function given in the Contour Surface within a Volume example. To emphasize the lower and upper values in the point cloud, the point cloud is added to the 3D axis by setting focus and span arguments, as shone in the hilighted line below.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm,colors,colormaps
from scipy.stats.qmc import Halton
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc
# 1. Get data to examine ...........................................
# 0. control parameters.
drez,N,seed,cmap = 3, 300, 6, 'jet'
domain = [ [-1,1], [-1,1], [-1,1] ]
# generate data points with values .
dt_coor = 2*Halton(3, seed=seed).random(N) - 1
vals = np.sum(dt_coor, axis=1)*np.exp(-3*np.sum(dt_coor**2, axis=1))
points = np.column_stack((dt_coor,vals))
# 2. Setup and map point cloud ....................................
cloudObj = ptc.Point3DCloud(drez,domain=domain)
cloudObj.map_vals_from_sampvals(points,cmap=cmap)
# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(10,4))
# ....................
fig.text(.27,0.9,'point cloud',ha='center')
ax = fig.add_subplot(121, projection='3d', aspect='equal')
ax.view_init(20,-60)
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],
xlabel='x',ylabel='y',zlabel='z')
cloudObj.add_to3d(ax,0,1,span=.65)
s3d.add_boxCorner(ax,domain)
# ....................
fig.text(.7,0.9,'samples ({})'.format(N),ha='center')
ax = fig.add_subplot(122, projection='3d', aspect='equal')
ax.view_init(20,-60)
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],
xlabel='x',ylabel='y',zlabel='z')
ax.scatter(*dt_coor.T, s=50, c=vals, cmap=cmap ,edgecolor='k')
s3d.add_boxCorner(ax,domain)
norm = colors.Normalize(np.min(vals),np.max(vals) )
cbar =fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax,shrink=0.8, pad=.1)
cbar.set_label('sample values', rotation=270, labelpad = 15)
# ....................
fig.tight_layout(pad=3)
plt.show()
