Drawing 3D graphics with matplotlib

a code

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import mpl_toolkits.mplot3d
  4. x,y = np.mgrid[-2:2:20j,-2:2:20j]
  5. #测试数据
  6. z=x*np.exp(-x**2-y**2)
  7. #三维图形
  8. ax = plt.subplot(111, projection='3d')
  9. ax.plot_surface(x,y,z,rstride=2, cstride=1, cmap=plt.cm.Blues_r)
  10. #设置坐标轴标签
  11. ax.set_xlabel('X')
  12. ax.set_ylabel('Y')
  13. ax.set_zlabel('Z')
  14. plt.show()
Second run results


 
three code
  1. import pylab as pl
  2. import numpy as np
  3. import mpl_toolkits.mplot3d
  4. rho, theta = np.mgrid[0:1:40j,0:2*np.pi:40j]
  5. z = rho**2
  6. x = rho*np.cos(theta)
  7. y = rho*np.sin(theta)
  8. ax = pl.subplot(111, projection='3d')
  9. #ax.plot_surface(x,y,z)
  10. ax.plot_surface(x,y,z,rstride=2, cstride=1)
  11. #设置坐标轴标签
  12. ax.set_xlabel('X')
  13. ax.set_ylabel('Y')
  14. ax.set_zlabel('Z')
  15. pl.show()
Four running results


 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327043848&siteId=291194637