mirror of
https://github.com/Estom/notes.git
synced 2026-04-05 03:48:56 +08:00
matplotlib & pandas
This commit is contained in:
42
Python/matplotlab/gallery/mplot3d/trisurf3d.md
Normal file
42
Python/matplotlab/gallery/mplot3d/trisurf3d.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# 三角三维曲面
|
||||
|
||||
用三角形网格绘制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
|
||||
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user