Files
notes_estom/Python/matplotlab/gallery/mplot3d/trisurf3d.md
2020-09-26 22:03:11 +08:00

42 lines
1.2 KiB
Markdown

# 三角三维曲面
用三角形网格绘制3D表面。
![三角三维曲面示例](https://matplotlib.org/_images/sphx_glr_trisurf3d_001.png)
```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
n_radii = 8
n_angles = 36
# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
radii = np.linspace(0.125, 1.0, n_radii)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)[..., np.newaxis]
# Convert polar (radii, angles) coords to cartesian (x, y) coords.
# (0, 0) is manually added at this stage, so there will be no duplicate
# points in the (x, y) plane.
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())
# Compute z to make the pringle surface.
z = np.sin(-x*y)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True)
plt.show()
```
## 下载这个示例
- [下载python源码: trisurf3d.py](https://matplotlib.org/_downloads/trisurf3d.py)
- [下载Jupyter notebook: trisurf3d.ipynb](https://matplotlib.org/_downloads/trisurf3d.ipynb)