from matplotlib import pyplot as plot
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
figure = plot.figure()
ax = Axes3D(figure) #创建3D对象
r = np.math.sqrt(1.5) #设置边界值
X = np.arange(-r, r, 0.01)
Y = np.arange(-r, r, 0.01)
X, Y = np.meshgrid(X, Y) #转化为二维坐标矩阵便于三维运算
Z = 1.5 - X*X - Y*Y #函数表达式
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
ax.plot_surface(X, Y, Z, cmap='rainbow') #设置图像参数,cmap是颜色,rainbow的效果就是彩色等高线
plot.show()