三角三维曲面

用三角形网格绘制3D表面。

三角三维曲面示例

  1. # This import registers the 3D projection, but is otherwise unused.
  2. from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. n_radii = 8
  6. n_angles = 36
  7. # Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
  8. radii = np.linspace(0.125, 1.0, n_radii)
  9. angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)[..., np.newaxis]
  10. # Convert polar (radii, angles) coords to cartesian (x, y) coords.
  11. # (0, 0) is manually added at this stage, so there will be no duplicate
  12. # points in the (x, y) plane.
  13. x = np.append(0, (radii*np.cos(angles)).flatten())
  14. y = np.append(0, (radii*np.sin(angles)).flatten())
  15. # Compute z to make the pringle surface.
  16. z = np.sin(-x*y)
  17. fig = plt.figure()
  18. ax = fig.gca(projection='3d')
  19. ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True)
  20. plt.show()

下载这个示例