1
- #!/usr/bin/env python
2
1
"""
3
2
Layer images above one another using alpha blending
4
3
"""
5
4
from __future__ import division
6
- from pylab import *
5
+ import matplotlib .pyplot as plt
6
+ import numpy as np
7
7
8
8
9
9
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 ))
11
11
12
12
# make these smaller to increase the resolution
13
13
dx , dy = 0.05 , 0.05
14
14
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 )
18
18
19
19
# when layering multiple images, the images need to have the same
20
20
# extent. This does not mean they need to have the same shape, but
@@ -24,20 +24,19 @@ def func3(x, y):
24
24
# interpolation edge effects
25
25
26
26
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 )
28
28
extent = xmin , xmax , ymin , ymax
29
29
fig = plt .figure (frameon = False )
30
30
31
- Z1 = array (([0 , 1 ]* 4 + [1 , 0 ]* 4 )* 4 )
31
+ Z1 = np . array (([0 , 1 ]* 4 + [1 , 0 ]* 4 )* 4 )
32
32
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 )
36
36
37
37
Z2 = func3 (X , Y )
38
38
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 )
42
41
43
- show ()
42
+ plt . show ()
0 commit comments