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. Define function to examine .....................................
def mfunc(xyz) :
x,y,z = xyz
return np.sin(x*y*z)/(x*y*z)
# 2. Setup and map cloud ............................................
drez, domain, nsurf = 6.5, 10, 3
cloudObj = ptc.Point3DCloud(drez,cmap='jet',domain=domain)
cloudObj.map_vals_from_op(mfunc,cmap='jet')
surface = cloudObj.valsurfSet(nsurf)
xlim,ylim,zlim = cloudObj.get_domain()
# 3. Construct figures, add cloud, and plot ........................
fig = plt.figure(figsize=(5.0, 4.5))
fig.text(0.975,0.975,str(cloudObj), ha='right', va='top', fontsize='smaller')
ax = fig.add_subplot(111, projection='3d', aspect='equal', focal_length=0.5)
ax.set(xlim=xlim,ylim=ylim,zlim=zlim,xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
ax.add_collection3d(surface.shade(ax=ax).hilite(.5,ax=ax))
s3d.add_boxCorner(ax,domain)
c,v,n = cloudObj.get_color_for_val(nsurf)
hnd = [ patches.Patch(label='value = {:.2f}'.format(v[i]), facecolor=c[i]) \
for i in range(nsurf) ]
ax.legend(handles=hnd)
fig.tight_layout(pad=1.5)
plt.show()