.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/images_contours_and_fields/quadmesh_demo.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_quadmesh_demo.py: ============= QuadMesh Demo ============= `~.axes.Axes.pcolormesh` uses a `~matplotlib.collections.QuadMesh`, a faster generalization of `~.axes.Axes.pcolor`, but with some restrictions. This demo illustrates a bug in quadmesh with masked data. .. GENERATED FROM PYTHON SOURCE LINES 11-44 .. code-block:: Python import numpy as np from matplotlib import pyplot as plt n = 12 x = np.linspace(-1.5, 1.5, n) y = np.linspace(-1.5, 1.5, n * 2) X, Y = np.meshgrid(x, y) Qx = np.cos(Y) - np.cos(X) Qz = np.sin(Y) + np.sin(X) Z = np.sqrt(X**2 + Y**2) / 5 Z = (Z - Z.min()) / (Z.max() - Z.min()) # The color array can include masked values. Zm = np.ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z) fig, axs = plt.subplots(nrows=1, ncols=3) axs[0].pcolormesh(Qx, Qz, Z, shading='gouraud') axs[0].set_title('Without masked values') # You can control the color of the masked region. cmap = plt.colormaps[plt.rcParams['image.cmap']].with_extremes(bad='y') axs[1].pcolormesh(Qx, Qz, Zm, shading='gouraud', cmap=cmap) axs[1].set_title('With masked values') # Or use the default, which is transparent. axs[2].pcolormesh(Qx, Qz, Zm, shading='gouraud') axs[2].set_title('With masked values') fig.tight_layout() plt.show() .. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_quadmesh_demo_001.png :alt: Without masked values, With masked values, With masked values :srcset: /gallery/images_contours_and_fields/images/sphx_glr_quadmesh_demo_001.png, /gallery/images_contours_and_fields/images/sphx_glr_quadmesh_demo_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.pcolormesh` / `matplotlib.pyplot.pcolormesh` .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.122 seconds) .. _sphx_glr_download_gallery_images_contours_and_fields_quadmesh_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: quadmesh_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: quadmesh_demo.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_