Contour Surfaces within a DomainΒΆ

../../_images/mp_box_conset.png

From the example 3D Box Surface Plot, a set of contour surfaces are generated within the domain.

import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d

#.. Matplotlib Examples: 3D box, set of contour surfaces

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

dmn = [ [0,100], [0,300],[-500,0] ]
def scalar_value(xyz) :
    X,Y,Z = xyz
    return  (((X+100)**2 + (Y-20)**2 + 2*Z)/1000+1)

# 2. Setup and map surface .........................................

surface = s3d.Surface3DCollection.implsurfSet(scalar_value, drez=2.0, domain=dmn, numb=9)

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

fig = plt.figure(figsize=(7.5, 6))
ax = plt.axes(projection='3d', aspect='equal', focal_length=0.5)
ax.set( xlabel='X [km]', ylabel='Y [km]', zlabel='Z [m]',
        zticks=[0, -150, -300, -450] )

ax.view_init(azim=-30)
minc, maxc = surface.bounds['vlim']
fig.colorbar(surface.cBar_ScalarMappable, ticks=np.linspace(minc,maxc,10),
    ax=ax, fraction=0.02, pad=0.1, label=surface.cname )

s3d.auto_scale(ax,surface)
ax.add_collection3d(surface.shade(direction=[1,2,0]) )

vE,iE = [ [0,0,0], [100,0,0], [100,300,0], [100,0,-500] ] ,  [ [0,1,2],[1,3]]
ax.add_collection3d( s3d.ColorLine3DCollection(vE,iE,color='0.6',lw=1) )

plt.show()