matplotlib & pandas

This commit is contained in:
estomm
2020-09-26 22:03:11 +08:00
parent 73cc328c81
commit d31be4f219
599 changed files with 99925 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
# Frontpage 3D示例
此示例再现Frontpage 3D示例。
![Frontpage 3D示例](https://matplotlib.org/_images/sphx_glr_3D_001.png)
```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)

View File

@@ -0,0 +1,39 @@
# Frontpage 轮廓示例
此示例再现Frontpage 轮廓示例。
![Frontpage 轮廓示例](https://matplotlib.org/_images/sphx_glr_contour_001.png)
```python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
extent = (-3, 3, -3, 3)
delta = 0.5
x = np.arange(-3.0, 4.001, delta)
y = np.arange(-4.0, 3.001, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = Z1 - Z2
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
fig, ax = plt.subplots()
cset1 = ax.contourf(
X, Y, Z, 40,
norm=norm)
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)
ax.set_xticks([])
ax.set_yticks([])
fig.savefig("contour_frontpage.png", dpi=25) # results in 160x120 px image
plt.show()
```
## 下载这个示例
- [下载python源码: contour.py](https://matplotlib.org/_downloads/contour.py)
- [下载Jupyter notebook: contour.ipynb](https://matplotlib.org/_downloads/contour.ipynb)

View File

@@ -0,0 +1,27 @@
# Frontpage 直方图示例
此示例再现Frontpage 直方图示例。
![Frontpage 直方图示例](https://matplotlib.org/_images/sphx_glr_histogram_001.png)
```python
import matplotlib.pyplot as plt
import numpy as np
random_state = np.random.RandomState(19680801)
X = random_state.randn(10000)
fig, ax = plt.subplots()
ax.hist(X, bins=25, density=True)
x = np.linspace(-5, 5, 1000)
ax.plot(x, 1 / np.sqrt(2*np.pi) * np.exp(-(x**2)/2), linewidth=4)
ax.set_xticks([])
ax.set_yticks([])
fig.savefig("histogram_frontpage.png", dpi=25) # results in 160x120 px image
```
## 下载这个示例
- [下载python源码: histogram.py](https://matplotlib.org/_downloads/histogram.py)
- [下载Jupyter notebook: histogram.ipynb](https://matplotlib.org/_downloads/histogram.ipynb)

View File

@@ -0,0 +1,29 @@
# Frontpage 绘图示例
此示例再现Frontpage 绘图示例。
![Frontpage 绘图示例](https://matplotlib.org/_images/sphx_glr_membrane_001.png)
```python
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import numpy as np
with cbook.get_sample_data('membrane.dat') as datafile:
x = np.fromfile(datafile, np.float32)
# 0.0005 is the sample interval
fig, ax = plt.subplots()
ax.plot(x, linewidth=4)
ax.set_xlim(5000, 6000)
ax.set_ylim(-0.6, 0.1)
ax.set_xticks([])
ax.set_yticks([])
fig.savefig("membrane_frontpage.png", dpi=25) # results in 160x120 px image
```
## 下载这个示例
- [下载python源码: membrane.py](https://matplotlib.org/_downloads/membrane.py)
- [下载Jupyter notebook: membrane.ipynb](https://matplotlib.org/_downloads/membrane.ipynb)