mirror of
https://github.com/Estom/notes.git
synced 2026-04-13 18:00:27 +08:00
matplotlib & pandas
This commit is contained in:
45
Python/matplotlab/gallery/frontpage/3D.md
Normal file
45
Python/matplotlab/gallery/frontpage/3D.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Frontpage 3D示例
|
||||
|
||||
此示例再现Frontpage 3D示例。
|
||||
|
||||

|
||||
|
||||
```python
|
||||
# This import registers the 3D projection, but is otherwise unused.
|
||||
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
|
||||
|
||||
from matplotlib import cbook
|
||||
from matplotlib import cm
|
||||
from matplotlib.colors import LightSource
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
filename = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)
|
||||
with np.load(filename) as dem:
|
||||
z = dem['elevation']
|
||||
nrows, ncols = z.shape
|
||||
x = np.linspace(dem['xmin'], dem['xmax'], ncols)
|
||||
y = np.linspace(dem['ymin'], dem['ymax'], nrows)
|
||||
x, y = np.meshgrid(x, y)
|
||||
|
||||
region = np.s_[5:50, 5:50]
|
||||
x, y, z = x[region], y[region], z[region]
|
||||
|
||||
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
|
||||
|
||||
ls = LightSource(270, 45)
|
||||
# To use a custom hillshading mode, override the built-in shading and pass
|
||||
# in the rgb colors of the shaded surface calculated from "shade".
|
||||
rgb = ls.shade(z, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')
|
||||
surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=rgb,
|
||||
linewidth=0, antialiased=False, shade=False)
|
||||
ax.set_xticks([])
|
||||
ax.set_yticks([])
|
||||
ax.set_zticks([])
|
||||
fig.savefig("surface3d_frontpage.png", dpi=25) # results in 160x120 px image
|
||||
```
|
||||
|
||||
## 下载这个示例
|
||||
|
||||
- [下载python源码: 3D.py](https://matplotlib.org/_downloads/3D.py)
|
||||
- [下载Jupyter notebook: 3D.ipynb](https://matplotlib.org/_downloads/3D.ipynb)
|
||||
Reference in New Issue
Block a user