Setting a domain for function PlotsΒΆ

Using the McCormick function which is defined in the domain as:

../../_images/mccormick.png

The simple plot, adjusting the domain and using auto scaling is:

../../_images/domain1.png
import numpy as np
from matplotlib import pyplot as plt
import s3dlib.surface as s3d

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

def McCormick_function(xyz) :
    x,y,z = xyz
    Z = np.sin(x+y) + (x-y)**2 - 1.5*x + 2.5*y + 1
    return x,y,Z

# 2. Setup and map surfaces .........................................
rez = 6

surface = s3d.PlanarSurface(rez).domain( (-1.5,4.0),(-3.0,4.0) )
surface.map_geom_from_op( McCormick_function )
surface.map_cmap_from_op( lambda C: C[2] , 'jet')

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

fig = plt.figure()
ax = plt.axes(projection='3d')
ax.view_init(25)
ax.set_title(surface.name, fontsize='x-large')
ax.set_xlabel('X')
ax.set_ylabel('Y')
s3d.auto_scale(ax,surface)

ax.add_collection3d(surface.shade(.5).hilite(.5))

plt.show()