
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/images_contours_and_fields/contour_corner_mask.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_images_contours_and_fields_contour_corner_mask.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_images_contours_and_fields_contour_corner_mask.py:


===================
Contour corner mask
===================

Illustrate the difference between ``corner_mask=False`` and
``corner_mask=True`` for masked contour plots.  The default is controlled by
:rc:`contour.corner_mask`.

.. GENERATED FROM PYTHON SOURCE LINES 10-42

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    # Data to plot.
    x, y = np.meshgrid(np.arange(7), np.arange(10))
    z = np.sin(0.5 * x) * np.cos(0.52 * y)

    # Mask various z values.
    mask = np.zeros_like(z, dtype=bool)
    mask[2, 3:5] = True
    mask[3:5, 4] = True
    mask[7, 2] = True
    mask[5, 0] = True
    mask[0, 6] = True
    z = np.ma.array(z, mask=mask)

    corner_masks = [False, True]
    fig, axs = plt.subplots(ncols=2)
    for ax, corner_mask in zip(axs, corner_masks):
        cs = ax.contourf(x, y, z, corner_mask=corner_mask)
        ax.contour(cs, colors='k')
        ax.set_title(f'{corner_mask=}')

        # Plot grid.
        ax.grid(c='k', ls='-', alpha=0.3)

        # Indicate masked points with red circles.
        ax.plot(np.ma.array(x, mask=~mask), y, 'ro')

    plt.show()




.. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_contour_corner_mask_001.png
   :alt: corner_mask=False, corner_mask=True
   :srcset: /gallery/images_contours_and_fields/images/sphx_glr_contour_corner_mask_001.png, /gallery/images_contours_and_fields/images/sphx_glr_contour_corner_mask_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 43-50

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.axes.Axes.contour` / `matplotlib.pyplot.contour`
   - `matplotlib.axes.Axes.contourf` / `matplotlib.pyplot.contourf`


.. _sphx_glr_download_gallery_images_contours_and_fields_contour_corner_mask.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: contour_corner_mask.ipynb <contour_corner_mask.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: contour_corner_mask.py <contour_corner_mask.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: contour_corner_mask.zip <contour_corner_mask.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
