1- #!/usr/bin/env python
21"""
32Layer images above one another using alpha blending
43"""
54from __future__ import division
6- from pylab import *
5+ import matplotlib .pyplot as plt
6+ import numpy as np
77
88
99def 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
1313dx , 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 )
2828extent = xmin , xmax , ymin , ymax
2929fig = 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 )
3232Z1 .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
3737Z2 = 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