3D箭袋图像

演示在3d网格上的点处绘制方向箭头。

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. fig = plt.figure()
  6. ax = fig.gca(projection='3d')
  7. # Make the grid
  8. x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2),
  9. np.arange(-0.8, 1, 0.2),
  10. np.arange(-0.8, 1, 0.8))
  11. # Make the direction data for the arrows
  12. u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
  13. v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
  14. w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
  15. np.sin(np.pi * z))
  16. ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True)
  17. plt.show()

下载这个示例