.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/images_contours_and_fields/layer_images.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_images_contours_and_fields_layer_images.py: ============ Layer Images ============ Layer images above one another using alpha blending .. GENERATED FROM PYTHON SOURCE LINES 8-44 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np def func3(x, y): return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2 + y**2)) # make these smaller to increase the resolution dx, dy = 0.05, 0.05 x = np.arange(-3.0, 3.0, dx) y = np.arange(-3.0, 3.0, dy) X, Y = np.meshgrid(x, y) # when layering multiple images, the images need to have the same # extent. This does not mean they need to have the same shape, but # they both need to render to the same coordinate system determined by # xmin, xmax, ymin, ymax. Note if you use different interpolations # for the images their apparent extent could be different due to # interpolation edge effects extent = np.min(x), np.max(x), np.min(y), np.max(y) fig = plt.figure(frameon=False) Z1 = np.add.outer(range(8), range(8)) % 2 # chessboard im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest', extent=extent) Z2 = func3(X, Y) im2 = plt.imshow(Z2, cmap=plt.cm.viridis, alpha=.9, interpolation='bilinear', extent=extent) plt.show() .. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_layer_images_001.png :alt: layer images :srcset: /gallery/images_contours_and_fields/images/sphx_glr_layer_images_001.png, /gallery/images_contours_and_fields/images/sphx_glr_layer_images_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-51 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.axes.Axes.imshow` / `matplotlib.pyplot.imshow` .. _sphx_glr_download_gallery_images_contours_and_fields_layer_images.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: layer_images.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: layer_images.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_