Vertical Contour Set 2ΒΆ

Mapping function definition was taken from the Mayavi surf demo example.

../../_images/b_demo.png
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
import s3dlib.cmap_utilities as cmu

#.. f(x,y) surface and z-contours.

# 1. Define function to examine .....................................

def mayDemo2(xyz) :
    x,y,z = xyz
    sin, cos = np.sin, np.cos
    Z = sin(x + y) + sin(2 * x - y) + cos(3 * x + 4 * y)
    return x,y,Z

# 2. Setup and map surfaces .........................................
rez=7
cmap = cmu.hue_cmap('b','r',2.0,name='BlRd')
surface = s3d.PlanarSurface(rez,'oct1',cmap=cmap).domain(7,5)
surface.map_geom_from_op(mayDemo2)
surface.map_cmap_from_op()

contours = surface.contourLineSet(3)

objects =[ surface, contours ]

# 3. Construct figure, add surface, and plot ......................

fig = plt.figure(figsize=(8,4))
info = str(surface) +'\n'+str(contours)
fig.text(0.98,0.98,info, ha='right', va='top')
for i in range(len(objects)) :
    ax =fig.add_subplot(121+i, projection='3d')
    ax.set_axis_off()
    ax.view_init(40,40)
    s3d.auto_scale(ax,surface,uscale=0.67)
    if i==0 : objects[i].shade(ax=ax,direction=[1,0,.5])
    else :    objects[i].fade(ax=ax)
    ax.add_collection3d(objects[i])

fig.tight_layout(pad=1)

plt.show()