Python基于matplotlib实现绘制三维图形功能示例
人气:0本文实例讲述了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.qb5200.com - 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 rho, theta = np.mgrid[0:1:40j,0:2*np.pi:40j] z = rho**2 x = rho*np.cos(theta) y = rho*np.sin(theta) ax = pl.subplot(111, projection='3d') ax.set_title('www.qb5200.com - matplotlib Demo'); #ax.plot_surface(x,y,z) ax.plot_surface(x,y,z,rstride=2, cstride=1) #设置坐标轴标签 ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') pl.show()
运行结果:
希望本文所述对大家Python程序设计有所帮助。
您可能感兴趣的文章:
加载全部内容