matplotlib.pyplot.plot_wireframe

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
"""
demo07_3d_wireframe.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))
# print(x, y)
# 计算每个坐标点的高度
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') # class axes3d
ax3d.set_xlabel('x', fontsize=14)
ax3d.set_ylabel('y', fontsize=14)
ax3d.set_zlabel('z', fontsize=14)
ax3d.plot_wireframe(x, y, z, cmap='jet', rstride=30, cstride=30)
plt.tick_params(labelsize=10)
# set spines invisible for error of tight_layout()
for spine in ax3d.spines.values():
spine.set_visible(False)
plt.tight_layout()
plt.savefig('3d_wireframe.png')
plt.show()