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. generate data samples with values .............................
N,seed,val_mult,domain = 50, 6, 25.0, [ [-7,6], [5,30], [0,50] ]
np.random.seed(seed)
xc = np.random.uniform(*domain[0], N)
yc = np.random.uniform(*domain[1], N)
zc = np.random.uniform(*domain[2], N)
dt_coor = np.column_stack((xc,yc,zc))
vals = val_mult*np.random.uniform(size=N)
points = np.column_stack((dt_coor,vals))
# 2. Setup and map surface .........................................
drez,numbSurf, vadj,cmap = 4, 3, 'c', 'jet'
cloudObj = ptc.Point3DCloud(drez,domain=domain)
cloudObj.map_vals_from_sampvals(points,vadj=vadj,cmap=cmap)
surface = cloudObj.valsurfSet( numbSurf)
# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(6,4.2))
ax = plt.axes(projection='3d', aspect='equal')
ax.view_init(20)
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],
xlabel='x',ylabel='y',zlabel='z')
ax.set_title('set of point cloud surfaces')
ax.add_collection3d(surface.shade(.1,ax=ax).hilite(.5,ax=ax))
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('cloud values', rotation=270, labelpad = 15)
c,v,_ = cloudObj.get_color_for_val(numbSurf)
hnd = [None]*numbSurf
for i in range(numbSurf) :
hnd[i] = patches.Patch(label='value = {:.2f}'.format(v[i]), color=c[i] )
ax.legend(handles=hnd)
fig.tight_layout()
plt.show()