
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/images_contours_and_fields/spy_demos.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_spy_demos.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_images_contours_and_fields_spy_demos.py:


=========
Spy Demos
=========

Plot the sparsity pattern of arrays.

.. GENERATED FROM PYTHON SOURCE LINES 8-33

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    # Fixing random state for reproducibility
    np.random.seed(19680801)

    fig, axs = plt.subplots(2, 2)
    ax1 = axs[0, 0]
    ax2 = axs[0, 1]
    ax3 = axs[1, 0]
    ax4 = axs[1, 1]

    x = np.random.randn(20, 20)
    x[5, :] = 0.
    x[:, 12] = 0.

    ax1.spy(x, markersize=5)
    ax2.spy(x, precision=0.1, markersize=5)

    ax3.spy(x)
    ax4.spy(x, precision=0.1)

    plt.show()




.. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_spy_demos_001.png
   :alt: spy demos
   :srcset: /gallery/images_contours_and_fields/images/sphx_glr_spy_demos_001.png, /gallery/images_contours_and_fields/images/sphx_glr_spy_demos_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 34-40

.. admonition:: References

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

   - `matplotlib.axes.Axes.spy` / `matplotlib.pyplot.spy`


.. _sphx_glr_download_gallery_images_contours_and_fields_spy_demos.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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