Contour Lines on a Contour SurfaceΒΆ
This example is similar to the Point Surface Set example , but in this case, contour lines on the z=planes are added to the figure. An example of:
a line.object created from a surface object which was created from a point-cloud object
Note: the drez argument in the cloud constructor was changed so that the surface face edges, created from the cloud, do not lie on the contour lines in the cloud domain.
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'
drez = 4.1 # reset, eliminating contours at computed surface edges.
cloudObj = ptc.Point3DCloud(drez,domain=domain)
cloudObj.map_vals_from_sampvals(points,vadj=vadj,cmap=cmap)
# 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('z-contour lines on point cloud contour surfaces')
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)
# line object from a surface object from a point-cloud object
surface = cloudObj.valsurfSet( numbSurf)
contours = surface.contourLineSet(5)
ax.add_collection3d( contours.fade(ax=ax) )
surface.set_surface_alpha(.1)
ax.add_collection3d(surface.shade(.1,ax=ax))
s3d.add_boxCorner(ax,domain)
fig.tight_layout()
plt.show()
