1"""
2============
3Layer Images
4============
5
6Layer images above one another using alpha blending
7"""
8from __future__ import division
9import matplotlib.pyplot as plt
10import numpy as np
11
12
13def func3(x, y):
14    return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2 + y**2))
15
16
17# make these smaller to increase the resolution
18dx, dy = 0.05, 0.05
19
20x = np.arange(-3.0, 3.0, dx)
21y = np.arange(-3.0, 3.0, dy)
22X, Y = np.meshgrid(x, y)
23
24# when layering multiple images, the images need to have the same
25# extent.  This does not mean they need to have the same shape, but
26# they both need to render to the same coordinate system determined by
27# xmin, xmax, ymin, ymax.  Note if you use different interpolations
28# for the images their apparent extent could be different due to
29# interpolation edge effects
30
31extent = np.min(x), np.max(x), np.min(y), np.max(y)
32fig = plt.figure(frameon=False)
33
34Z1 = np.add.outer(range(8), range(8)) % 2  # chessboard
35im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
36                 extent=extent)
37
38Z2 = func3(X, Y)
39
40im2 = plt.imshow(Z2, cmap=plt.cm.viridis, alpha=.9, interpolation='bilinear',
41                 extent=extent)
42
43plt.show()
44
45#############################################################################
46#
47# ------------
48#
49# References
50# """"""""""
51#
52# The use of the following functions and methods is shown
53# in this example:
54
55import matplotlib
56matplotlib.axes.Axes.imshow
57matplotlib.pyplot.imshow
58