Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 677646e

Browse files
committed
Merge pull request #4948 from ericmjl/mep12-layer_images.py
Mep12 layer images.py
2 parents 78c6865 + 6114b2d commit 677646e

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#!/usr/bin/env python
21
"""
32
Layer images above one another using alpha blending
43
"""
54
from __future__ import division
6-
from pylab import *
5+
import matplotlib.pyplot as plt
6+
import numpy as np
77

88

99
def func3(x, y):
10-
return (1 - x/2 + x**5 + y**3)*exp(-(x**2 + y**2))
10+
return (1 - x/2 + x**5 + y**3)*np.exp(-(x**2 + y**2))
1111

1212
# make these smaller to increase the resolution
1313
dx, dy = 0.05, 0.05
1414

15-
x = arange(-3.0, 3.0, dx)
16-
y = arange(-3.0, 3.0, dy)
17-
X, Y = meshgrid(x, y)
15+
x = np.arange(-3.0, 3.0, dx)
16+
y = np.arange(-3.0, 3.0, dy)
17+
X, Y = np.meshgrid(x, y)
1818

1919
# when layering multiple images, the images need to have the same
2020
# extent. This does not mean they need to have the same shape, but
@@ -24,20 +24,19 @@ def func3(x, y):
2424
# interpolation edge effects
2525

2626

27-
xmin, xmax, ymin, ymax = amin(x), amax(x), amin(y), amax(y)
27+
xmin, xmax, ymin, ymax = np.amin(x), np.amax(x), np.amin(y), np.amax(y)
2828
extent = xmin, xmax, ymin, ymax
2929
fig = plt.figure(frameon=False)
3030

31-
Z1 = array(([0, 1]*4 + [1, 0]*4)*4)
31+
Z1 = np.array(([0, 1]*4 + [1, 0]*4)*4)
3232
Z1.shape = (8, 8) # chessboard
33-
im1 = imshow(Z1, cmap=cm.gray, interpolation='nearest',
34-
extent=extent)
35-
hold(True)
33+
im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
34+
extent=extent)
35+
plt.hold(True)
3636

3737
Z2 = func3(X, Y)
3838

39-
im2 = imshow(Z2, cmap=cm.jet, alpha=.9, interpolation='bilinear',
40-
extent=extent)
41-
#axis([xmin, xmax, ymin, ymax])
39+
im2 = plt.imshow(Z2, cmap=plt.cm.jet, alpha=.9, interpolation='bilinear',
40+
extent=extent)
4241

43-
show()
42+
plt.show()

0 commit comments

Comments
 (0)