本文实例讲述了Python基于matplotlib实现绘制三维图形功能。分享给大家供大家参考,具体如下:
代码一:
# coding=utf-8
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d
x,y = np.mgrid[-2:2:20j,-2:2:20j]
#测试数据
z=x*np.exp(-x**2-y**2)
#三维图形
ax = plt.subplot(111, projection='3d')
ax.set_title('www.jb51.net - matplotlib Demo');
ax.plot_surface(x,y,z,rstride=2, cstride=1, cmap=plt.cm.Blues_r)
#设置坐标轴标签
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
运行结果:
代码二:
# coding=utf-8
import pylab as pl
import numpy as np
import mpl_toolkits.mplot3d
<