mirror of
https://github.com/Estom/notes.git
synced 2026-02-06 12:04:05 +08:00
36 lines
1.1 KiB
Markdown
36 lines
1.1 KiB
Markdown
# 3D箭袋图像
|
|
|
|
演示在3d网格上的点处绘制方向箭头。
|
|
|
|

|
|
|
|
```python
|
|
# This import registers the 3D projection, but is otherwise unused.
|
|
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
|
|
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
fig = plt.figure()
|
|
ax = fig.gca(projection='3d')
|
|
|
|
# Make the grid
|
|
x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2),
|
|
np.arange(-0.8, 1, 0.2),
|
|
np.arange(-0.8, 1, 0.8))
|
|
|
|
# Make the direction data for the arrows
|
|
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
|
|
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
|
|
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
|
|
np.sin(np.pi * z))
|
|
|
|
ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True)
|
|
|
|
plt.show()
|
|
```
|
|
|
|
## 下载这个示例
|
|
|
|
- [下载python源码: quiver3d.py](https://matplotlib.org/_downloads/quiver3d.py)
|
|
- [下载Jupyter notebook: quiver3d.ipynb](https://matplotlib.org/_downloads/quiver3d.ipynb) |