1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| """ demo07_3dsurface.py 3d 曲面图 """ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d import numpy as np
n = 500 x, y = np.meshgrid(np.linspace(-3, 3, n), np.linspace(-3, 3, n))
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)
plt.figure('3D surface', facecolor='lightgray') plt.title('3D Surface', fontsize=18) ax3d = plt.gca(projection='3d') ax3d.set_xlabel('x', fontsize=14) ax3d.set_ylabel('y', fontsize=14) ax3d.set_zlabel('z', fontsize=14) ax3d.plot_surface(x, y, z, cmap='jet', rstride=30, cstride=30) plt.tick_params(labelsize=10)
for spine in ax3d.spines.values(): spine.set_visible(False)
plt.tight_layout() plt.show()
|