Skip to content

Commit 44a6d1d

Browse files
committed
ENH new static images for the frontpage
Here is the code to produce the new static images for the website frontpage
1 parent 5203df6 commit 44a6d1d

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

examples/frontpage/plot_3D.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Demonstrates using custom hillshading in a 3D surface plot.
3+
"""
4+
from mpl_toolkits.mplot3d import Axes3D
5+
from matplotlib import cbook
6+
from matplotlib import cm
7+
from matplotlib.colors import LightSource
8+
import matplotlib.pyplot as plt
9+
import numpy as np
10+
11+
filename = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)
12+
with np.load(filename) as dem:
13+
z = dem['elevation']
14+
nrows, ncols = z.shape
15+
x = np.linspace(dem['xmin'], dem['xmax'], ncols)
16+
y = np.linspace(dem['ymin'], dem['ymax'], nrows)
17+
x, y = np.meshgrid(x, y)
18+
19+
region = np.s_[5:50, 5:50]
20+
x, y, z = x[region], y[region], z[region]
21+
22+
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
23+
24+
ls = LightSource(270, 45)
25+
# To use a custom hillshading mode, override the built-in shading and pass
26+
# in the rgb colors of the shaded surface calculated from "shade".
27+
rgb = ls.shade(z, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')
28+
surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=rgb,
29+
linewidth=0, antialiased=False, shade=False)
30+
ax.set_xticks([])
31+
ax.set_yticks([])
32+
ax.set_zticks([])
33+
fig.savefig("surface3D_frontpage.png")

examples/frontpage/plot_contour.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
from matplotlib import mlab, cm
4+
5+
# Default delta is large because that makes it fast, and it illustrates
6+
# the correct registration between image and contours.
7+
delta = 0.5
8+
9+
extent = (-3, 3, -3, 3)
10+
11+
x = np.arange(-3.0, 4.001, delta)
12+
y = np.arange(-4.0, 3.001, delta)
13+
X, Y = np.meshgrid(x, y)
14+
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, -0.5)
15+
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
16+
Z = (Z1 - Z2) * 10
17+
18+
levels = np.linspace(-2.0, 1.601, 40)
19+
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
20+
21+
fig, ax = plt.subplots()
22+
cset1 = ax.contourf(
23+
X, Y, Z, levels,
24+
norm=norm)
25+
ax.set_xlim(-3, 3)
26+
ax.set_ylim(-3, 3)
27+
ax.set_xticks([])
28+
ax.set_yticks([])
29+
fig.savefig("contour_frontpage.png")

examples/frontpage/plot_histogram.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
5+
random_state = np.random.RandomState(19680801)
6+
X = random_state.randn(10000)
7+
8+
fig, ax = plt.subplots()
9+
ax.hist(X, bins=25, normed=True)
10+
x = np.linspace(-5, 5, 1000)
11+
ax.plot(x, 1 / np.sqrt(2*np.pi) * np.exp(-(x**2)/2), linewidth=4)
12+
ax.set_xticks([])
13+
ax.set_yticks([])
14+
fig.savefig("histogram_frontpage.png")

examples/frontpage/plot_membrane.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import matplotlib.pyplot as plt
2+
import matplotlib.cbook as cbook
3+
import numpy as np
4+
5+
6+
datafile = cbook.get_sample_data('membrane.dat', asfileobj=False)
7+
x = np.fromstring(open(datafile, 'rb').read(), np.float32)
8+
# 0.0005 is the sample interval
9+
10+
fig, ax = plt.subplots()
11+
ax.plot(x, linewidth=4)
12+
ax.set_xlim(5000, 6000)
13+
ax.set_ylim(-0.6, 0.1)
14+
ax.set_xticks([])
15+
ax.set_yticks([])
16+
fig.savefig("membrane_frontpage.png")

0 commit comments

Comments
 (0)