import numpy as np
import matplotlib.pyplot as plt
# 中文的设置
import matplotlib as mp1
from mpl_toolkits.mplot3d import Axes3D
mp1.rcParams["font.sans-serif"] = ["kaiti"]
mp1.rcParams["axes.unicode_minus"] = False
# 数据创建
X = np.linspace(-5, 5, 100)
Y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(X, Y)
Z = X**2+Y**2
# 创建画布
f = plt.figure(dpi=200)
ax = f.add_subplot(1, 1, 1, projection='3d')
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow')
plt.colorbar(surf)
plt.show()
运行后结果如下: