例子代码如下:
import matplotlib.pyplot as plt def zfunc(x): return (x[0] ** 2 + x[1] - 11) ** 2 + (x[0] + x[1] ** 2 - 7) ** 2 # 可视化 x = np.arange(-6, 6, 0.1) y = np.arange(-6, 6, 0.1) print('x,y range:', x.shape, y.shape) X, Y = np.meshgrid(x, y) print('X,Y maps:', X.shape, Y.shape) Z = zfunc([X, Y]) flg = plt.figure('zfunc') ax = flg.add_subplot(projection='3d') ax.plot_surface(X, Y, Z) ax.view_init(-60, 30) ax.set_xlable = ('x') ax.set_ylable = ('y') plt.show()
图像如下:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)