Python绘制三维图形

需要安装numpy和matplotlib库,我都是pip库安装,这样比较简单。

import numpy as np
import matplotlib.pyplot as plt 
import mpl_toolkits.mplot3d

x, y = np.mgrid[-2 : 2 : 20j, -2 : 2 : 20j]
z = 50 * np.sin(x + y)                     # 测试数据
ax = plt.subplot(111, projection = '3d')   # 三维图形
ax.plot_surface(x, y, z, rstride = 2, cstride = 1, cmap = plt.cm.Blues_r)
ax.set_xlabel('x')                         # 设置坐标轴标签
ax.set_xlabel('y')
ax.set_xlabel('z')
plt.show()

这是最终效果

这里写图片描述

参考自《Python可以这样学》414页

猜你喜欢

转载自blog.csdn.net/magic_ninja/article/details/79718964